大提琴的声音就像一条河,左岸是我无法忘却的回忆,右岸是我值得紧握的璀璨年华,中间流淌的,是我年年岁岁淡淡的感伤
链接:https://ac.nowcoder.com/acm/problem/14585
来源:牛客网
题目描述
糖和抖m在玩个游戏,规定谁输了就要请谁吃顿大餐:抖m给糖a b c三个驻, 并在a柱上放置了数量为n的圆盘,圆盘的大小从上到下依次增大,现在要做的事就是把a柱的圆盘全部移到c柱,移动的过程中保持小盘在上,大盘在下,且限定圆盘只能够移动到相邻的柱子,即a柱子上的圆盘只能够移动到b,b柱子上的圆盘只能够移动到a或者c,c同理。现在请你设计一个程序,计算所需移动的最小步数, 帮助糖赢得大餐!
输入描述:
每一行输出有一个整数n(0<=n<26), 直至文件末尾。
输出描述:
对于每一组数据,输出一行,输出移动的最小步数M。
示例1
输入
复制
1
输出
复制
2
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int mod=1e9+7;
const int MAXN = 1e7;
ll jg;
int n;
void hanio(char a, char b, char c, int n) {
if(n==0)
return;
hanio(a,b,c,n-1);
jg++;
hanio(c,b,a,n-1);
jg++;
hanio(a,b,c,n-1);
}
int main() {
while(scanf("%d", &n)!=EOF) {
jg=0;
hanio('a','b','c',n);
cout<<jg<<endl;
}
return 0;
}
链接:https://ac.nowcoder.com/acm/problem/14587
来源:牛客网
题目描述
有天糖在学算法的时候,看到一种有意思的字符串,叫做“莫比乌斯串”, 这个串的特点是: 把从字符串的某一个位置把字符串截断, 并把前面的串放到后面构成新的串。比如有个串“asdasdf”, 它可以从‘d’那里截断,构成新串“asdfasd”,
现在你的任务是:判断给定的两个串是否为“莫比乌斯串”。
输入描述:
有多组测试数据,每组测试数据有两个字符串, 长度N<=1000
输出描述:
对于每一组数据,输出一行,如果两者能构成“莫比乌斯串”则输出“Yes”, 否则输出“No”。
示例1
输入
复制
1 asdasdf asdfasd
输出
复制
Yes
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int mod=1e9+7;
int n;
char n1[1010],n2[1010];
int diu(int st,int cd){
for(int i=1;i<cd;i++)
if(n1[(i+st+cd)%cd]!=n2[i])
return 0;
return 1;
}
int main(){
scanf("%d",&n);
while(n--){
scanf("%s",n1);
scanf("%s",n2);
int cd1=strlen(n1);
int cd2=strlen(n2);
if(!strcmp(n1,n2)){
printf("No\n");
continue;
}
int fg=0;
for(int i=1;i<cd1;i++){
if(n1[i]==n2[0]){
fg=diu(i,cd2);
if(fg)
break;
}
}
if(fg)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
链接:https://ac.nowcoder.com/acm/problem/14590
来源:牛客网
题目描述
之前的一天糖向图书馆借了一本书, 现在图书馆的工作人员要求糖立刻归还他借的书, 悲催的事, 糖不在学校, 跑到外面吃火锅去了, 所以糖想委托他的朋友去归还图书,你的任务就是判断糖是否能通过他的朋友归还书籍,能的话输出“Yes”, 否则输出“No”.
输入描述:
有t组数据, 每组开头有个数字n, m, x, y, n(n<=100)是里面人的编号,规定从1开始计算,编号为x代表糖,编号为y代表图书馆, 其余的代表的糖的朋友,接着有个m行 ,每行有两个数字,这个说明图书可以在这两者之间传递
输出描述:
对于每一组数据,输出一行,图书能归还成功输出“Yes”, 否则输出”No”。
示例1
输入
复制
1 3 2 1 3 1 2 2 3
输出
复制
Yes
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int mod=1e9+7;
int mp[110][110],vis[110];
int n,m,t,x,y,a,b;
int search(int st){
vis[st]=1;
if(st==y)
return 1;
for(int i=1;i<=n;i++){
if(mp[st][i]==1&&vis[i]==0){
if(search(i))
return 1;
}
}
return 0;
}
int main(){
cin>>t;
while(t--){
memset(mp,0,sizeof(mp));
memset(vis,0,sizeof(vis));
scanf("%d%d%d%d",&n,&m,&x,&y);
for(int i=0;i<m;i++){
scanf("%d%d",&a,&b);
mp[b][a]=mp[a][b]=1;
}
if(search(x)&&x!=y)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}