hdu1210Eddy's 洗牌问题 和 hdu 1209 Ignatius and the Princess IV 和hdu 1273漫步森林

来源:互联网 发布:降龙990数据恢复 编辑:程序博客网 时间:2024/05/28 15:07

hdu1210Eddy's 洗牌问题

//求交叉换位循环最后和原串相同的次数
#include <iostream>#include <string>#include <map>using namespace std;int main(){int n, i,j,k;int maxN, num;while(scanf("%d", &n) != EOF){ n *= 2;i = 1;num = 0;do{i = 2 * i % (n + 1);num++;}while( i != 1);printf("%d\n", num);}return 0;}


hdu 1029 Ignatius and the Princess IV
//求数组中出现次数过半的数
#include <iostream>#include <string>#include <map>using namespace std;int main(){int n, i, cur;int maxN, num;while(scanf("%d", &n) != EOF){scanf("%d", &maxN);num = 1;for (i = 1;i < n; ++i){scanf("%d", &cur);if (num == 0){num = 1;maxN = cur;}else{if (cur != maxN){num--;}else{num++;}}}printf("%d\n", maxN);}return 0;}



//hdu 1273漫步森林
#include <iostream>using namespace std;//一笔画的方式有多少种//就是每个节点的度数的一半//因为每次完整的一笔画都要消耗每个节点的2个度数int main(){int n;while(scanf("%d", &n) != EOF && n){printf("%d\n", (n - 1 ) /2);}return 0;}


原创粉丝点击