A. Bear and Raspberry

题意:找到相邻差值最大的差值。

分析:水题,直接做。

/****************************************
* File Name: 226a.cpp
* Author: sky0917
* Created Time: 2014年01月24日 23:33:21
****************************************/
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100005;int v[maxn];
int main(){int n, m;int a, b, c;int x;while (scanf("%d %d",&n,&x)!=EOF){int ma = 0;int re = 0;for (int i=0; i<n; i++){scanf("%d",&v[i]);}       for (int i=1; i<n; i++){if (v[i-1] - v[i] > re){re = v[i-1] - v[i];}}printf("%d\n",max(0, re-x));}   return 0;
}

View Code

B. Bear and Strings

题意:给出一个字符串 s (1 ≤ |s| ≤ 5000),问这个字符串中有多少个子串中含有至少一个“bear”单词。

分析:遍历一遍字符串,维护一个cnt,表示枚举的子串的开头位置的最左端

例如: acbeartbear

第一次发现 bear 之后,假如b的位置为 i ,那么:res += (i-cnt+1)*(len-i-3)

然后 cnt = i+1,这样就不会出现重复枚举的情况了。

/****************************************
* File Name: 226b.cpp
* Author: sky0917
* Created Time: 2014年01月24日 23:33:26
****************************************/
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 5005;char s[maxn];int main(){while (scanf("%s",&s)!=EOF){long long res = 0;long long len = strlen(s);long long cnt = 0;for (long long i=0; i<len-3; i++){if (s[i]=='b' && s[i+1]=='e' && s[i+2]=='a' && s[i+3]=='r'){long long l = i-cnt+1;long long r = len - i - 3;res += l * r;cnt = i+1;}   }printf("%I64d\n",res);}return 0;
}

View Code

C. Bear and Prime Numbers

题意:  有 n (1 ≤ n ≤ 106) 个数,x1, x2, ..., xn (2 ≤ xi ≤ 107). 还有 m (1 ≤ m ≤ 50000) 个询问,每个询问为:l,r

表示要求出[l, r]区间中所有的质数 p 的 f (p) 之和,f (p) 表示n个数中能被p整除的数的个数。

分析: 可以先打一个sqrt(1E7)范围的素数表,然后遍历一遍 n 个数,对每个数分解质因数,并用标记

数组标记,例如某个数有质因子 p,那么vis[p]++, 最后处理出一个sum[i] 数组,sum[i]表示vis[i]

数组中前 i 项的和,对于询问 l, r 输出 sum[r] - sum[l-1] 即可。

/****************************************
* File Name: 226c.cpp
* Author: sky0917
* Created Time: 2014年01月24日 23:33:45
****************************************/
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1000005;int ma;
int v[maxn*10];int vis[10003];
int p[10004];
int tp;
void print(){tp = 0;for (int i=2; i<10000; i++){if (!vis[i]){p[tp++] = i;for (int j=i*2; j<10000; j+=i){vis[j] = 1;}   }}
}
void cal(int x){for (int i=0; p[i]*p[i] <= x && i<tp; i++){if (x % p[i] == 0){v[p[i]]++;while (x % p[i] == 0){x /= p[i];          }   }   }if (x != 1){v[x]++;}
}int val[maxn];
int sum[maxn*10];
int main(){int n, m;int va;print();    while (scanf("%d",&n)!=EOF){ma = 0;for (int i=0; i<n; i++){scanf("%d",&val[i]);if (val[i] > ma)ma = val[i];}for (int i=0; i<n; i++){cal(val[i]);    }   for (int i=1; i<=ma; i++){sum[i] = sum[i-1] + v[i];}scanf("%d",&m);int l, r;while (m--){scanf("%d %d",&l, &r);if (l > ma){printf("0\n");continue;}r = min(ma, r);printf("%d\n",sum[r]-sum[l-1]); }}   return 0;
}

View Code

D. Bear and Floodlight

题意: 有 n(n<20) 个灯,每个灯有一个自己可以照亮的角度di,现在某个人要从(l,0) 走到(r,0)的位置,需要一开始调整

好灯的角度,使得这个人一路上都可以被灯照到,这个人走的路线是一条线段,问这个最多能走多远,当然最多不会超过

r 位置。

分析:状态压缩DP+向量旋转。

dp[st] 表示在 s 状态下,最远走的位置,s中..001010.. 1表示用了那个灯,0表示没用,然后枚举没有用的灯,让其

一开始的向量为(dp[st]-x0, -y0) 逆时针转 di 度得到新的向量,求出其和x轴的交点(x1,0)

那么dp[st|(1<<j)] = max(dp[st|(1<<j)], x1)

最后输出dp[st] 和 r 的最小值 再减去 l 就好。

注意一个情况,就是旋转过程中可能出现与x轴没有交点的情况,这个时候把 dp[st|(1<<j)] = r 就可以了。

/****************************************
* File Name: 226d.cpp
* Author: sky0917
* Created Time: 2014年01月25日  0:50:46
****************************************/
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const double p = acos(-1.0);
double dp[1<<21];
int n;
double l, r;
struct node{double x, y, di;
}q[22];int main(){while (scanf("%d %lf %lf",&n,&l,&r)!=EOF){for (int i=0; i<n; i++){scanf("%lf %lf %lf",&q[i].x,&q[i].y,&q[i].di);}int st = 1<<n;for (int i=0; i<st; i++){dp[i] = -9999999.0;}   dp[0] = l;for (int i=0; i<st; i++){for (int j=0; j<n; j++){if (((1<<j)&i) == 0){int sta = i | (1<<j);   double x = dp[i] - q[j].x;double y = -q[j].y;double a = x*cos(p*q[j].di/180)-y*sin(p*q[j].di/180);double b = x*sin(p*q[j].di/180)+y*cos(p*q[j].di/180);if (b >= 0){dp[sta] = r;continue;}double tmp = y*a/b+q[j].x;dp[sta] = max(dp[sta], tmp);}}}printf("%.10lf\n",min(r, dp[st-1])-l);}   return 0;
}

View Code

转载于:https://www.cnblogs.com/sky0917/p/3533204.html

Codeforces Round #226 (Div. 2)相关推荐

  1. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  2. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  3. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  4. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  5. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  6. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  7. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  8. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

  9. Codeforces Round #699 (Div. 2) (A ~ F)6题全,超高质量良心题解【每日亿题】2021/2/6

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) (A.B.C)[每日亿题]2021/2/ ...

  10. Codeforces Round #698 (Div. 2)(A ~ F)6题全,超高质量题解)【每日亿题】2021/2/4

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #698 (Div. 2)(A ~ F)6题全,超 ...

最新文章

  1. KVM虚拟机迁移到VMWare
  2. 函数参数传递常用的三种方式
  3. 【 C 】经典抽象数据类型(ADT)之堆栈(用静态数组实现堆栈)
  4. python 打包自己得到的结果
  5. Vagrant+VirtualBox版本的坑
  6. 使用Jmeter压力测试工具测试
  7. flume package遇到的问题
  8. 计算机网络西北大学,西北大学计算机网络复习资料(拟)
  9. CSS div 塌陷问题
  10. Python爬虫项目---从wiley网站批量下载文章
  11. ASP.NET中使用JQuery生成登陆验证码
  12. 表格求和和计算机不一致6,(电子行业企业管理)计算机电子表格公式应用常见错误及处理(6页)-原创力文档...
  13. 基于mt7621架构路由器编译auditord(生成ipk包)
  14. 知识图谱技术分享会----有关知识图谱构建的部分关键技术简介及思考
  15. python信用卡管理源码_Python随机生成信用卡卡号的实现方法
  16. 编写一个C语言程序 实现自我介绍,用c语言编程实现,别出心裁的情侣拍照
  17. vue 、前端rsa加密遇到的问题,message too long for RSA
  18. 【图像分类】实战——使用ResNet实现猫狗分类(pytorch)
  19. oa系统服务器什么意思,OA系统是什么意思
  20. pandas之describe函数分析

热门文章

  1. Ubuntu安装Apache+PHP
  2. (原)MobileNetV1
  3. Linux使用jstat命令查看jvm的GC情况(转)
  4. SVN入门 TortoiseSVN 检出
  5. Oracle 修改密码 解锁
  6. 施密特:乔布斯影响力还没有完全释放
  7. web标准设计工具:代码本地校验软件A Real Validator(附注册码)
  8. Civil3D二次开发常见问题总结
  9. EXTJS 5 开发环境搭建
  10. Mongodb Manual阅读笔记:CH6 聚合