codeforces-745【思维】
来源:互联网 发布:兄弟连高洛峰 php教程 编辑:程序博客网 时间:2024/05/16 12:56
题目链接:点击打开链接
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.
Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.
The first line of input will be a single string s (1 ≤ |s| ≤ 50), the word Hongcow initially learns how to spell. The string s consists only of lowercase English letters ('a'–'z').
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
abcd
4
bbb
1
yzyz
2
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
思路:把字符串按照题意做 len 次循环,然后判断有没有出现过就好了
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<map>using namespace std;string str;map<string,bool> M; int main(){while(cin>>str){M.clear();int len=str.length();//cout<<str.size()<<endl;int ans=0;for(int i=1;i<=len;i++){if(!M[str]){ans++;M[str]=1;}str=str[len-1]+str;str.erase(str.end()-1,str.end());}cout<<ans<<endl;}return 0;}/*#include<cstdio>#include<cstring>#include<algorithm>using namespace std;char str[55][55];int main(){while(~scanf("%s",str[0])){int len=strlen(str[0]);int ans=1;for(int i=1;i<len;i++){str[i][0]=str[i-1][len-1];for(int j=1;j<len;j++){str[i][j]=str[i-1][j-1];}bool flag=1;for(int j=0;j<i;j++){if(strcmp(str[i],str[j])==0){flag=0;break;}}if(flag)ans++;}printf("%d\n",ans);}return 0;}*/
题目链接:点击打开链接
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int n,m;char s[510][510];int main(){while(~scanf("%d%d",&n,&m)){int min_r=510,max_r=0;int min_c=510,max_c=0;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>s[i][j];if(s[i][j]=='X'){min_r=min(i,min_r);max_r=max(i,max_r);min_c=min(j,min_c);max_c=max(j,max_c);}}}bool flag=1;for(int i=min_r;i<=max_r;i++){for(int j=min_c;j<=max_c;j++){if(s[i][j]!='X'){flag=0;break;}}if(!flag)break;}if(flag)puts("YES");elseputs("NO");}return 0;}
- codeforces-745【思维】
- 思维 CodeForces
- [思维]CodeForces 135B
- Codeforces 611F 思维
- codeforces-660【思维】
- codeforces-554【思维】
- codeforces-632【思维】
- codeforces-597【思维】
- 【codeforces B + 思维】
- 【codeforces 723C】 + 思维
- codeforces-233【B思维】
- codeforces 734 (思维 暴力)
- codeforces C. Queue (思维)
- codeforces-746【思维】【模拟】
- codeforces-749【思维】
- codeforces-652【思维】
- codeforces-750【C思维】
- codeforces-754【A思维】
- Leetcode 84. Largest Rectangle in Histogram (Hard) (cpp)
- Html源文件查看器(Android)
- PHP中的数组(拆分与合并)
- Poedu_C语言提升_Lesson03_20161117_数据类型3
- MySQL的外键约束执行不了
- codeforces-745【思维】
- github pages + Hexo + 域名绑定搭建个人博客增强版
- 第 9 章 - 11 Domino Web服务器应用程序接口(DSAPI)
- MyBatis中的动态SQL
- 移动端与rem那些事
- windbg中通过文件句柄查找设备(!handle/!fileobj/!devobj命令)
- html盒子模型
- js的原型链与构造器
- ubuntu的快捷键