zoukankan      html  css  js  c++  java
  • 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
    ",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
    ",cas++,str[solve()]);
    50         }
    51     }
    52     return 0;
    53 }
    View Code

    end

  • 相关阅读:
    221. 最大正方形
    9. 回文数
    2. 两数相加
    1. 两数之和
    HDU 1864 最大报销额
    47 java包打成本地maven
    46 数组中的元素进行位置交换
    5 docker安装kibana
    45 vue图片放大预览
    4 docker中安装es
  • 原文地址:https://www.cnblogs.com/gaolzzxin/p/4931610.html
Copyright © 2011-2022 走看看