2015ACM/ICPC亚洲区沈阳站

http://acm.hdu.edu.cn/search.php?field=problem&key=2015ACM%2FICPC%D1%C7%D6%DE%C7%F8%C9%F2%D1%F4%D5%BE-%D6%D8%CF%D6%C8%FC%A3%A8%B8%D0%D0%BB%B6%AB%B1%B1%B4%F3%D1%A7%A3%A9&source=1&searchmode=source

 

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 }
View Code

 

 

 

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 }
View Code

 

 

end

转载于:https://www.cnblogs.com/gaolzzxin/p/4931610.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值