Codeforces Round #328 (Div. 2) A(模拟) B(数学) C(数学)
来源:互联网 发布:java compare返回结果 编辑:程序博客网 时间:2024/05/19 13:06
传送门:A. PawnChess
题意:有一个8*8棋盘,上面有W和B两种棋子,每个棋子可以上下左右移动,要求移动的位置必须为空即字符 . 。已知任意一个W到达第一行 或者 任意一个B到达第8行 均为胜,问你谁能获胜。
思路:模拟一下~
#include <bits/stdc++.h>using namespace std;char s[10][10];int main(){ for(int i=0; i<8; i++){ scanf("%s",s[i]); } int mina=inf,minb=inf; for(int i=0; i<8; i++){ for(int j=0; j<8; j++){ bool flag=false; if(s[i][j]=='W'){ flag=true; for(int k=i-1; k>=0; k--){ if(s[k][j]!='.')flag=false; } if(flag)mina=min(mina, i); } flag=false; if(s[i][j]=='B'){ flag=true; for(int k=i+1; k<8; k++){ if(s[k][j]!='.')flag=false; } if(flag)minb=min(minb, 7-i); } } } if(mina>minb)puts("B"); else puts("A"); return 0;}
传送门:B. The Monster and the Squirrel
题意:给定一个正n多边形,从它的顶点1引出一条射线,当碰到边、顶点反弹光线,问最后可以把多边形分成多少个区域。
思路:找规律列出前几个凸多边形-> (n-2) * (n-2)
#include <bits/stdc++.h>#define ll __int64using namespace std;int main(){ ll n; while(~scanf("%I64d",&n)){ printf("%I64d\n",(n-2)*(n-2)); } return 0;}
传送门:C. The Big Race
题意:
两个人A和B每个人每走一步的距离分别为w,b。现在给一个跑道,跑道后面是悬崖,人不能掉进悬崖。问最终A和B谁离起点越远谁获胜。
然后给一个长度L,问在长度L的范围里面,不能判断胜负的概率是多少。
解题思路:
1.当距离小于min(w,b)时,两人都在原点,不能判断出胜负。
2.当距离为w,b的最小公倍数时,即 lcm(w,b)时,不能判断出胜负。
3.当距离为 K*lcm(w,b)+min(w-1,b-1)时,两人都在 K * lcm(w,b)处,不能判断胜负。
4.当跳完最后一个满足 K*lcm(w,b)<=t的K时,后面有一段距离要巧妙的处理,这时候要取 min(min(w-1,b-1),t%lcm(w,b))。主要是避免 K * lcm(w,b) + min(w-1,b-1) > t的情况。
其中求lcm时,换成double型增大Long long 的范围。
感觉稍微有点难度的地方是第三点不好想。
#include<bits/stdc++.h>using namespace std;typedef long long LL;const double eps = 1e-9;LL gcd(LL a,LL b){ return b==0?a:gcd(b,a%b);}int main(){ LL t,w,b; cin>>t>>w>>b; LL tmp = gcd(w,b); LL ans = min(min(w-1,b-1),t); if(!(1.*w/tmp * b - t > eps)){ LL lcm = w/tmp *b; ans += t/lcm + (t/lcm-1)*min(w-1,b-1) + min(min(w-1,b-1),t%lcm); } LL now = gcd(ans,t); cout<<ans/now<<"/"<<t/now<<endl; return 0;}
1 0
- Codeforces Round #328 (Div. 2) A(模拟) B(数学) C(数学)
- Codeforces Round #392 (Div. 2) A(水)B(水、模拟) C(数学) D(贪心)
- Codeforces Round #282 (Div. 2) B.(数学)
- Codeforces Round #439 (Div. 2)(补题) A模拟+set B 数学 C dp or 杨辉三角组合数
- Codeforces Round #278 (Div. 2) B. Candy Boxes (模拟,数学)
- Codeforces Round #369 (Div. 2) B. Chris and Magic Square【数学,模拟】
- codeforces Round #377 div2 A B C(数学推导)
- Codeforces Round #195 (Div. 2) / 336A Vasily the Bear and Triangle(模拟&数学)
- Codeforces 715A & 716C Plus and Square Root【数学规律】 (Codeforces Round #372 (Div. 2))
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] C 数学
- Codeforces Round #196 (Div. 2) / 337B Routine Problem(数学)
- Codeforces Round #224 (Div. 2) B 数学推理
- Codeforces Round #340 (Div. 2)(B) 数学
- Codeforces Round #341 (Div. 2)(B)数学
- Codeforces Round #246 (Div. 2)(B)数学
- Codeforces Round #353 (Div. 2)-B. Restoring Painting(数学)
- Codeforces Round #319 (Div. 2)B. Modulo Sum(数学,DP)
- Codeforces Round #384 (Div. 2) B ,C ,D(规律,数学。树dp)
- 可视化网络安全技术“看透”黑客
- 智能厨房重构-使用Bmob后端云实现朋友圈的功能
- Working with the DOM
- OpenCV中的肤色检测
- 函数指针&指针函数
- Codeforces Round #328 (Div. 2) A(模拟) B(数学) C(数学)
- HDU1698 Just a Hook [lazy+成段更新]
- 导入Maven项目后,Eclipse提示“Missing artifact ”类的错误
- 省市区三级联动
- 【深入理解java集合系列】List,Set,Map用法以及区别
- svn学习
- 测试图片
- Scrapy爬虫Demo
- Eclipse中根据数据库自动生成dao、mapper、model