2015ACM/ICPC亚洲区沈阳站
B http://acm.hdu.edu.cn/showproblem.php?pid=5510
题意:
解法:
1 //#define debug 2 //#define txtout 3 #include<cstdio> 4 #include<cstdlib> 5 #include<cstring> 6 #include<cmath> 7 #include<cctype> 8 #include<ctime> 9 #include<iostream> 10 #include<algorithm> 11 #include<vector> 12 #include<queue> 13 #include<stack> 14 #include<map> 15 #include<set> 16 #define mt(a,b) memset(a,b,sizeof(a)) 17 using namespace std; 18 typedef long long LL; 19 const double eps=1e-8; 20 const double pi=acos(-1.0); 21 const int inf=0x3f3f3f3f; 22 const int M=1e5+10; 23 int n; 24 char a[512][2048]; 25 int solve() { 26 if(n==1) return -1; 27 int s=0,t=1,result=-1; 28 while(t<n){ 29 if(strstr(a[t],a[s])){ 30 s++; 31 if(s==t){ 32 t++; 33 } 34 continue; 35 } 36 result=max(result,t+1); 37 t++; 38 } 39 return result; 40 } 41 int main() { 42 #ifdef txtout 43 freopen("in.txt","r",stdin); 44 freopen("out.txt","w",stdout); 45 #endif 46 int t; 47 while(~scanf("%d",&t)) { 48 int cas=1; 49 while(t--) { 50 scanf("%d",&n); 51 for(int i=0; i<n; i++) { 52 scanf("%s",a[i]); 53 } 54 printf("Case #%d: %d\n",cas++,solve()); 55 } 56 } 57 return 0; 58 }
D http://acm.hdu.edu.cn/showproblem.php?pid=5512
题意:有n个楼,全坏了,现在下标a和b的修好了,Y和I轮流修剩下的坏的楼,一个楼只能被修一次,每次只能修下标为j-k或者j+k的,其中jk是任意两个已经修好的楼的下标。
解法:答案应该是所有能修的楼的个数,如果是奇数后手输,偶数先手输,关键在如何算出能修的楼的个数。可以不断的减,直至下标无法减小,然后用这个下标可以扩充出所有这个下标的倍数,那么假设d是可以构造的最小下标,那么能修的楼的个数就是n/d向下取整。至于构造d,就是辗转相减法求gcd,所以a和b的gcd就是能达到的最小下标。
1 //#define debug 2 //#define txtout 3 #include<cstdio> 4 #include<cstdlib> 5 #include<cstring> 6 #include<cmath> 7 #include<cctype> 8 #include<ctime> 9 #include<iostream> 10 #include<algorithm> 11 #include<vector> 12 #include<queue> 13 #include<stack> 14 #include<map> 15 #include<set> 16 #define mt(a,b) memset(a,b,sizeof(a)) 17 using namespace std; 18 typedef long long LL; 19 const double eps=1e-8; 20 const double pi=acos(-1.0); 21 const int inf=0x3f3f3f3f; 22 const int M=1e5+10; 23 int n,a,b; 24 char str[2][32]= {"Iaka","Yuwgna"}; 25 class Gcd_Lcm { ///最大公约数和最小公倍数 26 typedef int typec;///数类型 27 public: 28 typec gcd(typec a,typec b) { 29 return b?gcd(b,a%b):a; 30 } 31 typec lcm(typec a,typec b) { 32 return a/gcd(a,b)*b; 33 } 34 }gx; 35 int solve() { 36 a=gx.gcd(a,b); 37 return n/a%2; 38 } 39 int main() { 40 #ifdef txtout 41 freopen("in.txt","r",stdin); 42 freopen("out.txt","w",stdout); 43 #endif 44 int t; 45 while(~scanf("%d",&t)) { 46 int cas=1; 47 while(t--) { 48 scanf("%d%d%d",&n,&a,&b); 49 printf("Case #%d: %s\n",cas++,str[solve()]); 50 } 51 } 52 return 0; 53 }
end