D - Problem D. Euler Function(找规律)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322
Sample Input
2
1
2
Sample Output
5
7
【分析】
-
题意:给定一个k,找到第k小的与某个数互质的个数为合数。
扫描二维码关注公众号,回复: 2532769 查看本文章 -
找规律题。把前面几项列出来,会发现除了第一个对应的是5,接下来就是:
2 7
3 8
4 9
5 10
即前面一个数+5;
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int main(){
int t;
scanf("%d",&t);
while(t--)
{
long long k;
scanf("%lld",&k);
if(k==1)cout<<"5\n";
else cout<<k+5<<endl;
}
return 0;
}
F - Problem F. Grab The Tree(找规律,按位异或运算)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6324
【分析】
-
题意:有n个顶点的图,Q和T两人玩游戏,Q先拿走不相邻的若干点,剩下的全部给T,各自的得分为各自的顶点异或值。问最后谁赢
-
找规律的题。一开始在想图、树什么的,但是还是不用那样的咯。各自值的异或,加入Q为sum1,T为sum2,全部的点一个个 异或下来是sum,由于异或的结合律,sum1^sum2=sum。如果sum=0,则说明两个sum相等,即平局。否则,一定是Q赢。因为Q可取sum最高位1所对应的值所对应的顶点,剩下的必然小于该点,故Q必赢。所以只有两种结果。所以下面顶点的输入,,,一丢丢作用都没得的。只要求全部顶点的异或即可。
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,s=0,u,v,w;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&w);
s^=w;
}
for(int i=0;i<n-1;i++)
scanf("%d%d",&u,&v);
if(s==0)cout<<"D\n";
else cout<<"Q\n";
}
return 0;
}