Codeforces Round #258 (Div. 2) (掉分不开森啊不开森)
来源:互联网 发布:jre 7u45 windows x64 编辑:程序博客网 时间:2024/05/16 14:21
哎。又是2道,这次发挥的不好哎。。。
A. Game With Sticks
题意:有n根水平横着的木棍和m根垂直竖着的木棍交叉放着(图可进CF可见),然后两个人玩游戏,每次一个人取一个节点,然后原图中去除构成该节点的横向木棍和竖向木棍。问最后谁获胜。
思路:每次都取角落的节点,最后可知,只需判断min(n,m)的奇偶即可。
#include <stdio.h>int main(){ int n,m; char name[2][100]={"Akshat","Malvika"}; scanf("%d%d",&n,&m); int minh=min(n,m); if(minh%2) printf("%s\n",name[0]); else printf("%s\n",name[1]); return 0;}
B. Sort the Array
题意:对给定的一个数列,问能否逆转一次其中一段区间,使新数列成为递增数列。
思路:刚开始想麻烦了,想了半天还没写出来,后来发现只需要逆转一次,那么直接从前搜区间左端点,从后搜区间右端点即可。然后翻转,看是否符合要求。
#include <stdio.h>#include <queue>#include <string.h>#include <algorithm>using namespace std;int a[100005],b[100005];int n;bool judge(){ for(int i=0;i<n;i++) if(a[i]!=b[i]) return false; return true;}int main(){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&a[i]); b[i]=a[i]; } sort(b,b+n); if(judge()) printf("yes\n1 1\n"); else{ int st=n-1,ed=0; bool tag=true; for(int i=0;i<n;i++) if(a[i]!=b[i]){ st=i; break; } for(int i=n-1;i>=0;i--) if(a[i]!=b[i]){ ed=i; break; } if(st>ed) tag=false; else{ reverse(a+st,a+ed+1); if(!judge()) tag=false; } if(tag) printf("yes\n%d %d\n",st+1,ed+1); else printf("no\n"); } return 0;}
C. Predict Outcome of the Game
题意:给出n,k,d1,d2判断比赛结果。n为总比赛场数,k代表已经开始的场数,d1表示第一个队胜的场数和第二队的差的绝对值,d2表示表示第二个队胜的场数和第三队的差的绝对值。
思路:首先n必须为3的倍数。然后设第一个队前k场胜了x场,第二个队y场,第三个队z场。列出条件:1.abs(x-y)=d1,abs(y-z)=d2;2.x+y+z=k;3.0<=x,y,z<=n/3;
然后对x,y,z大小分类讨论,最后可知共四类。注意:数据大小,long long。
#include <stdio.h>#include <algorithm>using namespace std;long long n,k,d1,d2;bool ok1(){//判断当x>=y>=z时 if((k-d1-2*d2)>=0&&(k-d1-2*d2)%3==0&&(k+d1*2+d2)<=n) return true; return false;}bool ok2(){//判断x>=y&&z>=y时 if((k-d1-d2)>=0&&(k-d1-d2)%3==0&&((k-d1-d2)/3)+max(d1,d2)<=n/3) return true; return false;}bool ok3(){//判断y>=x&&y>=z if((k+d1+d2)%3==0&&(k+d1+d2)<=n&&(k+d1+d2)/3>=max(d1,d2)) return true; return false;}bool ok4(){//判断z>=y>=x时 if((k+d1-d2)%3==0&&(k+d1-d2)/3>=d1&&(k+d1-d2)<=(n-3*d2)) return true; return false;}int main(){ long long t; scanf("%I64d",&t); while(t--){ scanf("%I64d%I64d%I64d%I64d",&n,&k,&d1,&d2); if(n%3) printf("no\n"); else{ if(ok1()||ok2()||ok3()||ok4()) printf("yes\n"); else printf("no\n"); } } return 0;}
哎,还是太弱了。C本应该写出来的。
0 0
- Codeforces Round #258 (Div. 2) (掉分不开森啊不开森)
- Codeforces Round #258 (Div. 2)
- Codeforces Round #258 (Div. 2)
- Codeforces Round #258 (Div. 2)
- Codeforces Round #258 (Div. 2)
- Codeforces Round #258 (Div. 2)
- 【索引】Codeforces Round #258 (Div. 2)
- Codeforces Round #258 (Div. 2)[ABCD]
- Codeforces Round #258 (Div. 2) C, D
- Codeforces Round #258 (Div. 2) B C
- Codeforces Round #258 (Div. 2) 总结
- Codeforces Round #258 (Div. 2)题解
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- 3555555555555
- 无状态的“长连接”模式实现手游的网络通信
- 【TOJ 2421.】 Sylvester construction【水题】
- ubuntu的tinyos的配置安装
- First day in tencent
- Codeforces Round #258 (Div. 2) (掉分不开森啊不开森)
- Prüfer编码与Cayley公式
- 瀑涛囱脸徽蛹肺皆轮站秃凑呢嘏丫
- 常见应用层协议端口号
- 扑职匠逞蓝坦倨碧纶裁嘶孔亓偎拇
- 朴卧睾低恍拇涌皆帘拙啄烁加徒偕
- 猜褂痰来琴挥局浊轮谋沦夹刮甲魏
- N种常见损坏电脑的行为
- chrome离线安装