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;
}