最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

CodeforcesRound#280(Div.2)_html/css

来源:懂视网 责编:小采 时间:2020-11-27 15:59:14
文档

CodeforcesRound#280(Div.2)_html/css

CodeforcesRound#280(Div.2)_html/css_WEB-ITnose:这场题简单的令人吃惊 ABC几乎都是签到题 D的话 把两个人的射击时间转化成整数 求个gcd,除一下。 假设两人的射击频率分别是1秒x,1秒y x,y的gcd为g 转化一下就相当于 第一个人 y/g 秒射一发, 第二个人x/g秒射一发 然后两个人在 x/g*y/g 秒时会
推荐度:
导读CodeforcesRound#280(Div.2)_html/css_WEB-ITnose:这场题简单的令人吃惊 ABC几乎都是签到题 D的话 把两个人的射击时间转化成整数 求个gcd,除一下。 假设两人的射击频率分别是1秒x,1秒y x,y的gcd为g 转化一下就相当于 第一个人 y/g 秒射一发, 第二个人x/g秒射一发 然后两个人在 x/g*y/g 秒时会

这场题简单的令人吃惊


ABC几乎都是签到题


D的话

把两个人的射击时间转化成整数

求个gcd,除一下。

假设两人的射击频率分别是1秒x,1秒y

x,y的gcd为g

转化一下就相当于

第一个人 y/g 秒射一发, 第二个人x/g秒射一发

然后两个人在 x/g*y/g 秒时会同时射击

那么每个x/g*y/g秒就是一个周期了

假设怪物的血有a,那么a%(x+y)就是最后一个周期要射击的血量

在这个时候我已经懒得继续思考了, 直接去二分某个人射击的次数,就OK了


#include #include #include #include #include #include #include #define MAXN 55555#define MAXM 222222#define INF 1000000001using namespace std;int n, x, y, a;int main() { scanf("%d%d%d", &n, &x, &y); int g = __gcd(x, y); x /= g; y /= g; for(int i = 0; i < n; i++) { scanf("%d", &a); a %= (x + y); if(a == 0 || (a + 1) % (x + y) == 0) puts("Both"); else { int flag = 0; int low = 1, high = x; while(low <= high) { int mid = (low + high) >> 1; long long tmp = (long long)mid * (long long)y; long long z = tmp / (long long)x; if(z + mid > a) { high = mid - 1; } else if(z + mid == a) { flag = 1; break; } else { low = mid + 1; } } if(flag) { puts("Vanya"); } else { puts("Vova"); } } } return 0;}



E的话

题目给出了很好的限制了

就是从x方向或者y方向,你从0开始走,走个n步,一定能遍历到所有的0~n-1

然后x方向你从0模拟走个n步,得到一个x坐标序列

y坐标也这么干

两个序列。都是可以循环的

然后你选择从某个点(x0,y0)出发

无非就是对两个序列,x序列的从x0开始,y序列从y0开始,各自走个n步,看有哪些点是符合题目要求的

再一看,发现无非就是看两个序列的相对位置了。

对所有给出的点, 算出其对应的 两个序列的相对位置,最后统计下即可


#include #include #include #include #include #include #include #define MAXN 55555#define MAXM 222222#define INF 1000000001using namespace std;int posx[1111111], posy[1111111];int n, m, dx, dy;int x[111111], y[111111];int num[1111111];int main() { scanf("%d%d%d%d", &n, &m, &dx, &dy); int now = 0; int ind = 0; while(posx[now] == 0) { posx[now] = ++ind; now = (now + dx) % n; } now = 0, ind = 0; while(posy[now] == 0) { posy[now] = ++ind; now = (now + dy) % n; } int mx = 0, p = 0; for(int i = 0; i < m; i++) { scanf("%d%d", &x[i], &y[i]); int px = posx[x[i]]; int py = posy[y[i]]; int t = (py - px + n) % n; num[t]++; if(num[t] > mx) { mx = num[t]; p = t; } } for(int i = 0; i < m; i++) { int px = posx[x[i]]; int py = posy[y[i]]; int t = (py - px + n) % n; if(t == p) { printf("%d %d\n", x[i], y[i]); break; } } return 0;}

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

CodeforcesRound#280(Div.2)_html/css

CodeforcesRound#280(Div.2)_html/css_WEB-ITnose:这场题简单的令人吃惊 ABC几乎都是签到题 D的话 把两个人的射击时间转化成整数 求个gcd,除一下。 假设两人的射击频率分别是1秒x,1秒y x,y的gcd为g 转化一下就相当于 第一个人 y/g 秒射一发, 第二个人x/g秒射一发 然后两个人在 x/g*y/g 秒时会
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top