Codeforces Round #376 (Div. 2) A.B
来源:互联网 发布:阿里云 dnspod 编辑:程序博客网 时间:2024/06/08 12:25
A题
题意:
给出一个字符串,询问在a开始,转动转盘需要最少多少步可以转出这个字符串。(每次转完不返回a)
#include <iostream>#include <stdio.h>#include <cstring>#include <queue>#include <stack>#include <algorithm>#include <math.h>using namespace std;char a[105];int main(){ gets(a); int it=0; int sum=0; for(int i=0;i<strlen(a);i++) { if(a[i]-'a'==it) continue; int t1=a[i]-'a'-it; int t2=it-(a[i]-'a'); if(t1<0) t1+=26; if(t2<0) t2+=26; if(t1<t2) { sum+=t1; } else sum+=t2; it=a[i]-'a'; } cout<<sum<<endl; return 0;}
B题
题意:
给出两种方案买PIZZA 。 第一种,买二的倍数个PIZZA。第二种买今天的一个PIZZA ,明天也必须在订单中先买一个PIZZA。注意最后一天如果自己单独买PIZZA,不能买一个PIZZA。当然如果倒数第二天买了一个,最后一天可以单独买一个。
思路:
2的倍数,做标记
#include <iostream>#include <stdio.h>#include <cstring>#include <queue>#include <stack>#include <algorithm>using namespace std;int a[200050];int main(){ int n; cin>>n; for(int i=1;i<=n;i++) scanf("%d",&a[i]); int fg=0; int over=0; if(a[1]%2==1) { fg=1; } for(int i=2;i<=n;i++) { if(fg==1) { a[i]--; if(a[i]<0) { over=1; break; } } a[i]=a[i]%2; if(a[i]==1) { fg=1; } else fg=0; } if(fg==1) { printf("NO\n"); } else { if(over==1) { printf("NO\n"); } else printf("YES\n"); } return 0;}
0 0
- Codeforces Round #376 (Div. 2) A.B
- Codeforces Round #376 (Div. 2) A && B
- Codeforces Round #376 (Div. 2)(A+B)
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #216 (Div. 2) A.B
- Codeforces round #236Div.2--A;B
- Codeforces Round #236 (Div. 2)------A,B
- Codeforces Round #237 (Div. 2) A & B
- Codeforces Round #247 (Div. 2) A B
- Codeforces Round #251 (Div. 2) A~B
- Codeforces Round #249 (Div. 2) A B
- Codeforces Round #271 (Div. 2)-A.B
- Codeforces Round #202 (Div. 2) A,B
- Codeforces Round #277 (Div. 2) A B
- Codeforces Round #278 (Div. 2) A B
- Codeforces Round #278 (Div. 2) A, B
- Codeforces Round #281 (Div. 2) A B
- 51单片机—定时器显示时钟
- 使用文件上传类upload.php上传文件
- 01串
- 【bzoj 1748】[Ahoi2009]Seq 维护序列seq 裸的线段树
- R语言图形编程
- Codeforces Round #376 (Div. 2) A.B
- 找回自己
- 城市的三级列表
- word2013中公式居中编号右对齐
- Object-Oriented Analysis and Design Using UML 翻译与学习 (六)
- 时钟类
- Python字典排序
- 五月一战
- Python编码