2018年南京站

题目链接:http://codeforces.com/gym/101981

A题:

思路:

  通过枚举n<=5的情况可以发现,只有当k==1且n为偶数时或者n==0时后手胜,其他的都是先手胜。

代码实现如下:

 1 #include <set>
 2 #include <map>
 3 #include <deque>
 4 #include <queue>
 5 #include <stack>
 6 #include <cmath>
 7 #include <ctime>
 8 #include <bitset>
 9 #include <cstdio>
10 #include <string>
11 #include <vector>
12 #include <cstdlib>
13 #include <cstring>
14 #include <iostream>
15 #include <algorithm>
16 using namespace std;
17 
18 typedef long long LL;
19 typedef pair<LL, LL> pLL;
20 typedef pair<LL, int> pli;
21 typedef pair<int, LL> pil;;
22 typedef pair<int, int> pii;
23 typedef unsigned long long uLL;
24 
25 #define lson rt<<1
26 #define rson rt<<1|1
27 #define lowbit(x) x&(-x)
28 #define  name2str(name) (#name)
29 #define bug printf("*********\n")
30 #define debug(x) cout<<#x"=["<<x<<"]" <<endl
31 #define FIN freopen("D://code//in.txt", "r", stdin)
32 #define IO ios::sync_with_stdio(false),cin.tie(0)
33 
34 const double eps = 1e-8;
35 const int mod = 1000000007;
36 const int maxn = 2000 + 7;
37 const double pi = acos(-1);
38 const int inf = 0x3f3f3f3f;
39 const LL INF = 0x3f3f3f3f3f3f3f3fLL;
40 
41 int n, k;
42 
43 int main() {
44     scanf("%d%d", &n, &k);
45     if(n == 0 || (k == 1 && n % 2 == 0)) printf("Austin\n");
46     else printf("Adrien\n");
47     return 0;
48 }
View Code

D题:

思路:

  最小球覆盖或三分套三分再套三分。

代码实现如下:

最小球覆盖:

 1 #include <set>
 2 #include <map>
 3 #include <deque>
 4 #include <queue>
 5 #include <stack>
 6 #include <cmath>
 7 #include <ctime>
 8 #include <bitset>
 9 #include <cstdio>
10 #include <string>
11 #include <vector>
12 #include <cstdlib>
13 #include <cstring>
14 #include <iostream>
15 #include <algorithm>
16 using namespace std;
17 
18 typedef long long LL;
19 typedef pair<LL, LL> pLL;
20 typedef pair<LL, int> pli;
21 typedef pair<int, LL> pil;;
22 typedef pair<int, int> pii;
23 typedef unsigned long long uLL;
24 
25 #define lson rt<<1
26 #define rson rt<<1|1
27 #define lowbit(x) x&(-x)
28 #define  name2str(name) (#name)
29 #define bug printf("*********\n")
30 #define debug(x) cout<<#x"=["<<x<<"]" <<endl
31 #define FIN freopen("D://code//in.txt", "r", stdin)
32 #define IO ios::sync_with_stdio(false),cin.tie(0)
33 
34 const double eps = 1e-8;
35 const int mod = 1000000007;
36 const int maxn = 1e6 + 7;
37 const int mx = 8e4 + 7;
38 const double pi = acos(-1);
39 const int inf = 0x3f3f3f3f;
40 const LL INF = 0x3f3f3f3f3f3f3f3fLL;
41 
42 int n;
43 
44 struct Point {
45     int x, y, z;
46 }pp[107];
47 
48 struct Point1 {
49     double x, y, z;
50 }nw;
51 
52 double dis(Point1 a, Point b) {
53     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z));
54 }
55 
56 double solve(int n) {
57     int idx = 1;
58     nw.x = nw.y = nw.z = 0;
59     double tmp = 10000.0, ans = 1e30;
60     while(tmp > eps) {
61         for(int i = 1; i <= n; i++) {
62             if(dis(nw, pp[i]) - dis(nw, pp[idx]) >= eps) {
63                 idx = i;
64             }
65         }
66         double cnt = dis(nw, pp[idx]);
67         if(ans - cnt >= eps) ans = cnt;
68         nw.x += (pp[idx].x - nw.x) / cnt * tmp;
69         nw.y += (pp[idx].y - nw.y) / cnt * tmp;
70         nw.z += (pp[idx].z - nw.z) / cnt * tmp;
71         tmp *= 0.99;
72     }
73     return ans;
74 }
75 
76 int main() {
77 #ifndef ONLINE_JUDGE
78     FIN;
79 #endif
80     scanf("%d", &n);
81     for(int i = 1; i <= n; i++) {
82         scanf("%d%d%d", &pp[i].x, &pp[i].y, &pp[i].z);
83     }
84     printf("%.9f\n", solve(n));
85     return 0;
86 }
View Code

G题:

思路:

  C(n+3,4);

代码实现如下:

 1 #include <set>
 2 #include <map>
 3 #include <queue>
 4 #include <set>
 5 #include <map>
 6 #include <deque>
 7 #include <queue>
 8 #include <stack>
 9 #include <cmath>
10 #include <ctime>
11 #include <bitset>
12 #include <cstdio>
13 #include <string>
14 #include <vector>
15 #include <cstdlib>
16 #include <cstring>
17 #include <iostream>
18 #include <algorithm>
19 using namespace std;
20 
21 typedef long long LL;
22 typedef pair<LL, LL> pLL;
23 typedef pair<LL, int> pli;
24 typedef pair<int, LL> pil;;
25 typedef pair<int, int> pii;
26 typedef unsigned long long uLL;
27 
28 #define lson rt<<1
29 #define rson rt<<1|1
30 #define lowbit(x) x&(-x)
31 #define  name2str(name) (#name)
32 #define bug printf("*********\n")
33 #define debug(x) cout<<#x"=["<<x<<"]" <<endl
34 #define FIN freopen("D://code//in.txt", "r", stdin)
35 #define IO ios::sync_with_stdio(false),cin.tie(0)
36 
37 const double eps = 1e-8;
38 const int mod = 1000000007;
39 const int maxn = 1e5 + 7;
40 const double pi = acos ( -1 );
41 const int inf = 0x3f3f3f3f;
42 const LL INF = 0x3f3f3f3f3f3f3f3fLL;
43 int t;
44 LL n;
45 
46 int Mod_Pow(int x, int n) {
47     int res = 1;
48     while(n) {
49         if(n & 1) res = 1LL * x * res % mod;
50         x = 1LL * x * x % mod;
51         n >>= 1;
52     }
53     return res;
54 }
55 
56 int main() {
57     int tmp = Mod_Pow(24, mod - 2);
58     scanf("%d",&t);
59     while(t--){
60         scanf("%lld",&n);
61         printf("%lld\n",((((n+3)*(n+2)%mod)*(n+1)%mod)*(n)%mod * tmp) % mod);
62     }
63     return 0;
64 }
View Code

I题:

思路:

  网络流。

代码实现如下:

  1 #include <set>
  2 #include <map>
  3 #include <deque>
  4 #include <queue>
  5 #include <stack>
  6 #include <cmath>
  7 #include <ctime>
  8 #include <bitset>
  9 #include <cstdio>
 10 #include <string>
 11 #include <vector>
 12 #include <cstdlib>
 13 #include <cstring>
 14 #include <iostream>
 15 #include <algorithm>
 16 using namespace std;
 17 
 18 typedef long long LL;
 19 typedef pair<LL, LL> pLL;
 20 typedef pair<LL, int> pli;
 21 typedef pair<int, LL> pil;;
 22 typedef pair<int, int> pii;
 23 typedef unsigned long long uLL;
 24 
 25 #define lson rt<<1
 26 #define rson rt<<1|1
 27 #define lowbit(x) x&(-x)
 28 #define  name2str(name) (#name)
 29 #define bug printf("*********\n")
 30 #define debug(x) cout<<#x"=["<<x<<"]" <<endl
 31 #define FIN freopen("D://code//in.txt", "r", stdin)
 32 #define IO ios::sync_with_stdio(false),cin.tie(0)
 33 
 34 const double eps = 1e-8;
 35 const int mod = 1000000007;
 36 const int maxn = 2000 + 7;
 37 const double pi = acos(-1);
 38 const int inf = 0x3f3f3f3f;
 39 const LL INF = 0x3f3f3f3f3f3f3f3fLL;
 40 
 41 int n, m, k, num, x;
 42 
 43 struct Dinic {
 44     queue<int> q;
 45     int maxflow, tot, s, t;
 46     int head[maxn], d[maxn];
 47     void init() {
 48         tot = maxflow = 0;
 49         memset(d, 0, sizeof(d));
 50         memset(head, -1, sizeof(head));
 51     }
 52     struct edge {
 53         int v, w, next;
 54     }ed[maxn*maxn];
 55     void addedge(int u, int v, int w) {
 56         ed[tot].v = v;
 57         ed[tot].w = w;
 58         ed[tot].next = head[u];
 59         head[u] = tot++;
 60         ed[tot].v = u;
 61         ed[tot].w = 0;
 62         ed[tot].next = head[v];
 63         head[v] = tot++;
 64     }
 65     bool bfs() {
 66         memset(d, 0, sizeof(d));
 67         d[s] = 1;
 68         while(!q.empty()) q.pop();
 69         q.push(s);
 70         while(!q.empty()) {
 71             int x = q.front();
 72             q.pop();
 73             for(int i = head[x]; ~i; i = ed[i].next) {
 74                 if(ed[i].w && !d[ed[i].v]) {
 75                     d[ed[i].v] = d[x] + 1;
 76                     q.push(ed[i].v);
 77                     if(ed[i].v == t) return 1;
 78                 }
 79             }
 80         }
 81         return 0;
 82     }
 83     int dinic(int x, int flow) {
 84         if(x == t) return flow;
 85         int res = flow, k;
 86         for(int i = head[x]; ~i && res; i = ed[i].next) {
 87             int v = ed[i].v;
 88             if(ed[i].w && d[v] == d[x] + 1) {
 89                 k = dinic(v, min(res, ed[i].w));
 90                 if(!k) d[v] = 0;
 91                 ed[i].w -= k;
 92                 ed[i^1].w += k;
 93                 res -= k;
 94             }
 95         }
 96         return flow - res;
 97     }
 98     int work() {
 99         int flow = 0;
100         while(bfs()) {
101             while(flow = dinic(s, inf)) maxflow += flow;
102         }
103         return maxflow;
104     }
105 }f;
106 
107 
108 int main() {
109 #ifndef ONLINE_JUDGE
110     FIN;
111 #endif
112     scanf("%d%d%d", &n, &m, &k);
113     f.init();
114     f.s = 0, f.t = 2 * n + m + 2;
115     f.addedge(0, 1, k);
116     for(int i = 1; i <= n; i++) {
117         f.addedge(0, i + 1, 1);
118         f.addedge(1, i + n + 1, 1);
119         scanf("%d", &num);
120         for(int j = 1; j <= num; j++) {
121             scanf("%d", &x);
122             f.addedge(i + 1, 2 * n + 1 + x, 1);
123             f.addedge(i + n + 1, 2 * n + 1 + x, 1);
124         }
125     }
126     for(int i = 1; i <= m; i++) {
127         f.addedge(i + 2 * n + 1, f.t, 1);
128     }
129     printf("%d\n", f.work());
130     return 0;
131 }
View Code

J题:

思路:

  预处理出每个数的素因子,然后记录每个素因子出现的位置,对于每个素因子的贡献为(v[i][j] - v[i][j-1])*(n - v[i][j] + 1)。

代码实现如下:

 1 #include <set>
 2 #include <map>
 3 #include <deque>
 4 #include <queue>
 5 #include <stack>
 6 #include <cmath>
 7 #include <ctime>
 8 #include <bitset>
 9 #include <cstdio>
10 #include <string>
11 #include <vector>
12 #include <cstdlib>
13 #include <cstring>
14 #include <iostream>
15 #include <algorithm>
16 using namespace std;
17 
18 typedef long long LL;
19 typedef pair<LL, LL> pLL;
20 typedef pair<LL, int> pli;
21 typedef pair<int, LL> pil;;
22 typedef pair<int, int> pii;
23 typedef unsigned long long uLL;
24 
25 #define lson rt<<1
26 #define rson rt<<1|1
27 #define lowbit(x) x&(-x)
28 #define  name2str(name) (#name)
29 #define bug printf("*********\n")
30 #define debug(x) cout<<#x"=["<<x<<"]" <<endl
31 #define FIN freopen("D://code//in.txt", "r", stdin)
32 #define IO ios::sync_with_stdio(false),cin.tie(0)
33 
34 const double eps = 1e-8;
35 const int mod = 1000000007;
36 const int maxn = 1e6 + 7;
37 const int mx = 8e4 + 7;
38 const double pi = acos(-1);
39 const int inf = 0x3f3f3f3f;
40 const LL INF = 0x3f3f3f3f3f3f3f3fLL;
41 
42 int n;
43 int a[maxn], p[maxn], vis[maxn];
44 vector<int> ans[maxn], v[maxn], st;
45 
46 void init() {
47     for(int i = 2; i < maxn; i++) p[i] = 1;
48     for(int i = 2; i < maxn; i++) {
49         if(p[i]) {
50             ans[i].push_back(i);
51             for(int j = 2*i; j < maxn; j += i) {
52                 ans[j].push_back(i);
53                 p[j] = 0;
54             }
55         }
56     }
57 }
58 
59 int main() {
60     init();
61     scanf("%d", &n);
62     for(int i = 1; i <= n; i++) {
63         scanf("%d", &a[i]);
64         int x = ans[a[i]].size();
65         for(int j = 0; j < x; j++) {
66             st.push_back(ans[a[i]][j]);
67         }
68     }
69     LL sum = 0;
70     sort(st.begin(), st.end());
71     st.erase(unique(st.begin(), st.end()), st.end());
72     int sz = st.size();
73     for(int i = 0; i < sz; i++) {
74         vis[st[i]] = i;
75     }
76     for(int i = 1; i <= n; i++) {
77         int x = ans[a[i]].size();
78         for(int j = 0; j < x; j++) {
79             v[vis[ans[a[i]][j]]].push_back(i);
80         }
81     }
82     for(int i = 0; i < sz; i++) {
83         int pp = v[i].size();
84         for(int j = 0; j < pp; j++) {
85             if(j == 0) {
86                 sum += 1LL * v[i][j] * (n - v[i][j] + 1);
87             } else {
88                 sum += 1LL * (v[i][j] - v[i][j-1]) * (n - v[i][j] + 1);
89             }
90         }
91     }
92     printf("%lld\n", sum);
93     return 0;
94 }
View Code

 K题:

思路:

  逗你玩题,随机长度为5e4的序列即可。

代码实现如下:

 1 #include <set>
 2 #include <map>
 3 #include <deque>
 4 #include <queue>
 5 #include <stack>
 6 #include <cmath>
 7 #include <ctime>
 8 #include <bitset>
 9 #include <cstdio>
10 #include <string>
11 #include <vector>
12 #include <cstdlib>
13 #include <cstring>
14 #include <iostream>
15 #include <algorithm>
16 using namespace std;
17 
18 typedef long long LL;
19 typedef pair<LL, LL> pLL;
20 typedef pair<LL, int> pli;
21 typedef pair<int, LL> pil;;
22 typedef pair<int, int> pii;
23 typedef unsigned long long uLL;
24 
25 #define lson rt<<1
26 #define rson rt<<1|1
27 #define lowbit(x) x&(-x)
28 #define  name2str(name) (#name)
29 #define bug printf("*********\n")
30 #define debug(x) cout<<#x"=["<<x<<"]" <<endl
31 #define FIN freopen("D://code//in.txt", "r", stdin)
32 #define IO ios::sync_with_stdio(false),cin.tie(0)
33 
34 const double eps = 1e-8;
35 const int mod = 1000000007;
36 const int maxn = 1e5 + 7;
37 const double pi = acos(-1);
38 const int inf = 0x3f3f3f3f;
39 const LL INF = 0x3f3f3f3f3f3f3f3fLL;
40 
41 int n, m;
42 int a[25][25];
43 char s[] = {'L', 'U', 'R', 'D'};
44 
45 int main() {
46     srand(time(0));
47     scanf("%d%d", &n, &m);
48     for(int i = 1; i <= n; i++) {
49         for(int j = 1; j <= m; j++) {
50             scanf("%1d", &a[i][j]);
51         }
52     }
53     int x;
54     for(int i = 1; i <= 50000; i++) {
55         x = rand() % 4;
56         printf("%c", s[x]);
57     }
58     printf("\n");
59     return 0;
60 }
View Code
posted @ 2018-11-18 15:46  Dillonh  阅读(214)  评论(0编辑  收藏  举报