The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online Solution

A    Live Love

水。

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 typedef long long ll;
 6 const double eps = 1e-8;
 7 const int INF = 0x3f3f3f3f;
 8 const ll MOD = (int)1e9 + 7;
 9 const int maxn = (int)1e6 + 10;
10 
11 int n, m;
12 
13 inline void RUN()
14 {
15     int t;
16     scanf("%d", &t);
17     while (t--)
18     {
19         scanf("%d %d", &n, &m);
20         int ans1 = m;
21         int ans2 = (n) / (n - m + 1);
22         printf("%d %d\n", ans1, ans2);
23     }
24 }
25 
26 int main()
27 {
28 #ifdef LOCAL_JUDGE
29     freopen("Text.txt", "r", stdin);
30 #endif // LOCAL_JUDGE
31 
32     RUN();
33 
34 #ifdef LOCAL_JUDGE
35     fclose(stdin);
36 #endif // LOCAL_JUDGE
37     return 0;
38 }
View Code
B Red Black Tree

题意:有一个树,上面有红点和黑点,有边权,每个点的花费定义为它到离它最近的红点的距离,每次询问给出一些点,能够将这棵树中的一个黑点变为红点,使得这些点中的最大花费最小

思路:二分答案,符合条件的点不管,将不符合条件的点LCA求出来,变红,然后算距离

C Halting Problem

题意:

思路:

  1 #include<bits/stdc++.h>
  2 
  3 using namespace std;
  4 
  5 typedef long long ll;
  6 const double eps = 1e-8;
  7 const int INF = 0x3f3f3f3f;
  8 const ll MOD = (int)1e9 + 7;
  9 const int maxn = (int)1e4 + 10;
 10 
 11 int n, num;
 12 int vis[maxn][260];
 13 struct node {
 14     char op[10];
 15     int v, k;
 16 }arr[maxn];
 17 
 18 inline void RUN()
 19 {
 20     int t;
 21     scanf("%d", &t);
 22     while (t--)
 23     {
 24         scanf("%d", &n);
 25         for (int i = 1; i <= n; ++i)
 26         {
 27             for (int j = 0; j < 256; ++j)
 28             {
 29                 vis[i][j] = 0;
 30             }
 31         }
 32         int flag = true;
 33         int s = 0;
 34         int now = 1;
 35         for (int i = 1; i <= n; ++i)
 36         {
 37             scanf("%s", arr[i].op);
 38             if (strcmp(arr[i].op,"add") == 0)
 39             {
 40                 scanf("%d", &arr[i].v);
 41                 arr[i].k = 0;
 42             }
 43             else
 44             {
 45                 scanf("%d %d", &arr[i].v, &arr[i].k);
 46             }
 47         }
 48         while (1)
 49         {
 50             if (now == n + 1)
 51             {
 52                 flag = true;
 53                 break;
 54             }
 55             if (vis[now][s])
 56             {
 57                 flag = false;
 58                 break;
 59             }
 60             vis[now][s]++;
 61             if (strcmp(arr[now].op, "add") == 0)
 62             {
 63                 s = (s + arr[now].v);
 64                 if (s >= 256)s -= 256;
 65                 now++;
 66             }
 67             else if (strcmp(arr[now].op, "beq") == 0)
 68             {
 69                 if (s == arr[now].v)
 70                 {
 71                     now = arr[now].k;
 72                 }
 73                 else
 74                 {
 75                     now++;
 76                 }
 77             }
 78             else if (strcmp(arr[now].op, "bne") == 0)
 79             {
 80                 if (s != arr[now].v)
 81                 {
 82                     now = arr[now].k;
 83                 }
 84                 else
 85                 {
 86                     now++;
 87                 }
 88             }
 89             else if (strcmp(arr[now].op, "blt") == 0)
 90             {
 91                 if (s < arr[now].v)
 92                 {
 93                     now = arr[now].k;
 94                 }
 95                 else
 96                 {
 97                     now++;
 98                 }
 99             }
100             else if (strcmp(arr[now].op, "bgt") == 0)
101             {
102                 if (s > arr[now].v)
103                 {
104                     now = arr[now].k;
105                 }
106                 else
107                 {
108                     now++;
109                 }
110             }
111         }
112         puts(flag ? "Yes" : "No");
113     }
114 }
115 
116 int main()
117 {
118 #ifdef LOCAL_JUDGE
119     freopen("Text.txt", "r", stdin);
120 #endif // LOCAL_JUDGE
121 
122     RUN();
123 
124 #ifdef LOCAL_JUDGE
125     fclose(stdin);
126 #endif // LOCAL_JUDGE
127     return 0;
128 }
View Code
D Pixel Art

留坑。

E Infinite Parenthesis Sequence

留坑。

F Chaleur

留坑。

G Couleur

留坑。

H Traveling on the Axis

题意:一个字符串表示当前点是红灯还是绿灯,灯一秒变一次,求$\sum_{p = 0}^{n - 1}\sum_{q = p +1}^{n} t(p, q)$

思路:前缀搞一搞

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 char st[100000+10];
 6 long long f[100000+10];
 7 int main() {
 8     long long t,n,i,j,k;
 9     long long ans;
10     scanf("%lld",&t);
11     while (t--) {
12         scanf("%s",st);
13         n=strlen(st);
14         f[1]=1; ans=0;
15         for (i=1;i<n;++i) 
16             if (st[i]==st[i-1]) f[i+1]=2;
17             else f[i+1]=1;
18         for (i=1;i<=n;++i) {
19             ans+=(f[i])*i*(n-i+1);
20             if (st[i-1]=='0') ans+=n-i+1;
21             if (f[i]==2) ans-=n-i+1;
22         }
23         printf("%lld\n",ans);
24     }
25     return 0;
26 }
View Code
J Press the Button

题意:周期性按灯,每按一次,如果灯本来是亮着就++, 求最后+了多少次

思路:

  1 #include<bits/stdc++.h>
  2 
  3 using namespace std;
  4 
  5 typedef long long ll;
  6 const double eps = 1e-8;
  7 const int INF = 0x3f3f3f3f;
  8 const ll MOD = (int)1e9 + 7;
  9 const int maxn = (int)1e4 + 10;
 10 
 11 inline ll gcd(ll a, ll b)
 12 {
 13     return b == 0 ? a : gcd(b, a%b);
 14 }
 15 
 16 ll a, b, c, d, v, t;
 17 
 18 inline void RUN()
 19 {
 20     int cas;
 21     scanf("%d", &cas);
 22     while (cas--)
 23     {
 24         scanf("%lld %lld %lld %lld %lld %lld", &a, &b, &c, &d, &v, &t);
 25         ll G = gcd(a, c);
 26         G = a * c / G;
 27         //cout << G << endl;
 28         ll res =0;
 29         ll res1 =  b - 1 + d;
 30         ll len = t / G;
 31         ll M = t % G;
 32         ll t1 = a;
 33         ll t2 = c;
 34         ll now = 0;
 35         while (t1 <= G && t2 <= G)
 36         {
 37             if (t1 < t2)
 38             {
 39                 ll tmp = t1 - now;
 40                 if (tmp > v)
 41                 {
 42                     res += b - 1;
 43                     if (t1 <= M)
 44                     {
 45                         res1 += b - 1;
 46                     }
 47                 }
 48                 else
 49                 {
 50                     res += b;
 51                     if (t1 <= M)
 52                     {
 53                         res1 += b;
 54                     }
 55                 }
 56                 now = t1;
 57                 t1 += a;
 58 
 59             }
 60             else if (t1 > t2)
 61             {
 62                 ll tmp = t2 - now;
 63                 if (tmp > v)
 64                 {
 65                     res += d - 1;
 66                     if (t2 <= M)
 67                     {
 68                         res1 += d - 1;
 69                     }
 70                 }
 71                 else
 72                 {
 73                     res += d;
 74                     if (t2 <= M)
 75                     {
 76                         res1 += d;
 77                     }
 78                 }
 79                 now = t2;
 80                 t2 += c;
 81             }
 82             else if (t1 == t2)
 83             {
 84                 ll tmp = t1 - now;
 85                 if (tmp > v)
 86                 {
 87                     res += b + d - 1;
 88                     if (t1 <= M)
 89                     {
 90                         res1 += b + d - 1;
 91                     }
 92                 }
 93                 else
 94                 {
 95                     res += b + d;
 96                     if (t1 <= M)
 97                     {
 98                         res1 += b + d;
 99                     }
100                 }
101                 now = t1;
102                 t1 += a;
103                 t2 += c;
104 
105             }
106         }
107         ll ans = res * len + res1;
108         printf("%lld\n", ans);
109     }
110 }
111 
112 int main()
113 {
114 #ifdef LOCAL_JUDGE
115     freopen("Text.txt", "r", stdin);
116 #endif // LOCAL_JUDGE
117 
118     RUN();
119 
120 #ifdef LOCAL_JUDGE
121     fclose(stdin);
122 #endif // LOCAL_JUDGE
123     return 0;
124 }
View Code
K XOR Clique

题意:给出n个数,求选出一个点集,使得里面的点两两异或不超过这两个数中小的那个,求点集里面元素个数最大是多少

思路:枚举最高位

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 typedef long long ll;
 6 const double eps = 1e-8;
 7 const int INF = 0x3f3f3f3f;
 8 const ll MOD = (int)1e9 + 7;
 9 const int maxn = (int)1e6 + 10;
10 
11 int n, num;
12 int arr[40];
13 
14 inline void RUN()
15 {
16     int t;
17     scanf("%d", &t);
18     while (t--)
19     {
20         int ans = 0;
21         scanf("%d", &n);
22         memset(arr, 0, sizeof arr);
23         for (int i = 1; i <= n; ++i)
24         {
25             scanf("%d", &num);
26             int cnt = 0;
27             while (num)
28             {
29                 cnt++;
30                 num >>= 1;
31             }
32             arr[cnt]++;
33             ans = max(ans, arr[cnt]);
34         }
35         printf("%d\n", ans);
36     }
37 }
38 
39 int main()
40 {
41 #ifdef LOCAL_JUDGE
42     freopen("Text.txt", "r", stdin);
43 #endif // LOCAL_JUDGE
44 
45     RUN();
46 
47 #ifdef LOCAL_JUDGE
48     fclose(stdin);
49 #endif // LOCAL_JUDGE
50     return 0;
51 }
View Code

猜你喜欢

转载自www.cnblogs.com/Dup4/p/9657033.html