2015ACM/ICPC亚洲区上海站

时间:2023-03-09 19:25:03
2015ACM/ICPC亚洲区上海站

5573  Binary Tree(构造)

题意:给你一个二叉树,根节点为1,子节点为父节点的2倍和2倍+1,从根节点开始依次向下走k层,问如何走使得将路径上的数进行加减最终结果得到n。

联想到二进制。

思路和这个差不多吧:http://blog.csdn.net/u013068502/article/details/50094561

#include <set>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
#define mem(x,y) memset(x, y, sizeof(x))
#define lson l,m,rt << 1
#define rson m+1,r,rt << 1 | 1
 ? a : gcd(b, a % b);}
int lcm(int a, int b){return a / gcd(a, b) * b;}
int main()
{
    int T;
    scanf("%d", &T);
    ; cas <= T; cas++)
    {
        ;
        scanf("%d%d", &n, &k);
         == )
        {
             n--;
             flag = ;
        }
        LL all = ( << (k + )) - ;
        LL res = (all - n) >> ;
        printf("Case #%d:\n", cas);
        ; i < k; i++)
        {
            LL temp =  << i;
            )) printf( : temp);
            ) printf("%I64d -\n", temp);
            else printf("%I64d +\n", temp);
            res >>= ;
        }
    }
    ;
}            

5578  Friendship of Frog

题意:给你一个字符串,找最近的相同字符

 #include <set>
 #include <cmath>
 #include <queue>
 #include <cstdio>
 #include <vector>
 #include <cstring>
 #include <algorithm>
 using namespace std;
 typedef long long LL;
 #define mem(x,y) memset(x, y, sizeof(x))
 #define lson l,m,rt << 1
 #define rson m+1,r,rt << 1 | 1
  ? a : gcd(b, a % b);}
 int lcm(int a, int b){return a / gcd(a, b) * b;}
 const int INF = 0x3f3f3f3f;
 ];
 int main()
 {
     int T;
     scanf("%d", &T);
     getchar();
     ; cas <= T; cas++)
     {
         scanf("%s", s);
         int len = strlen(s);
         int ans = INF;
         ; i < len; i++)
         {
             ; j < len; j++)
             {
                 if(s[i] == s[j])
                 {
                     ans = min(ans, abs(i - j));
                 }
             }
         }
         printf( : ans);
     }
     ;
 }

5583  Kingdom of Black and White

题意:给你一个01字符串,要求最多改变一个字符(即0->1或1->0),使相邻相同字符的平方和最大

漏了考虑,改变中间一个区间之后,两个到三个区间变成相同字符的情况。WA了。

 #include <set>
 #include <cmath>
 #include <queue>
 #include <cstdio>
 #include <vector>
 #include <cstring>
 #include <algorithm>
 using namespace std;
 typedef long long LL;
 #define mem(x,y) memset(x, y, sizeof(x))
 #define lson l,m,rt << 1
 #define rson m+1,r,rt << 1 | 1
  ? a : gcd(b, a % b);}
 int lcm(int a, int b){return a / gcd(a, b) * b;}
 ;
 int s[maxn];
 LL len[maxn];
 int main()
 {
     int T;
     scanf("%d", &T);
     getchar();
     ; cas <= T; cas++)
     {
         mem(s, -);
         char ch;
         ;
         while(~scanf("%c", &ch))
         {
             if(ch == '\n') break;
             s[slen++] = ch - ';
         }
         , cur = , cnt = ;
         while(cur <= slen)
         {
             ])
             {
                 len[cnt++] = cur - temp;
                 temp = cur;
             }
             cur++;
         }
         LL ans = ;
         ; i < cnt; i++)
         {
             ans += len[i] * len[i];
         }
         LL rec = ans;
         ; i < cnt; i++)
         {
             ) break;
             ] ==  && i != )
             {
                 ans = max(ans,
                           rec - len[i - ] * len[i - ] - len[i - ] * len[i - ] - len[i] * len[i]
                           + (len[i - ] + len[i - ] + len[i]) * (len[i - ] + len[i - ] + len[i]));
             }
             ])
             {
                 ans = max(ans, rec +  * (len[i - ] - len[i] + ));
             }
             ])
             {
                 ans = max(ans, rec +  * (len[i] - len[i - ] + ));
             }
         }
         printf("Case #%d: %I64d\n", cas, ans);

     }
     ;
 }

5584  LCM Walk(数学推导)

题意:有一只青蛙,它从起点(x,y)出发,每次它会走  LCM(x,y)  步到达点  (x+LCM(x,y),y)  或点  (x,y+LCM(x,y))  ,最终,它会到达点(ex,ey),现给你终点(ex,ey),要你求出它的起点有多少种可能。

 #include <set>
 #include <cmath>
 #include <queue>
 #include <cstdio>
 #include <vector>
 #include <cstring>
 #include <algorithm>
 using namespace std;
 typedef long long LL;
 #define mem(x,y) memset(x, y, sizeof(x))
 #define lson l,m,rt << 1
 #define rson m+1,r,rt << 1 | 1
  ? a : gcd(b, a % b);}
 int lcm(int a, int b){return a / gcd(a, b) * b;}
 ;

 int main()
 {
     int T, fx, fy;
     scanf("%d", &T);
     ; cas <= T; cas++)
     {
         scanf("%d%d", &fx, &fy);
         LL ans = ;
         )
         {
             int g = gcd(fx, fy);
             if(fy > fx) swap(fx, fy);
             ) break;
             int m1 = fx / (fy + g);
             int m2 = fy / g;
             fx = m1 * g;
             fy = m2 * g;
             ans++;
         }
         printf();
     }
     ;
 }