2015多校第二场

1002 特殊情况

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <cassert>
 6 using namespace std;
 7 typedef long long ll;
 8 const int mo=1e9+7;
 9 int pow(int a,int b,int c){int ret=1;for(;b;b>>=1,a=1LL*a*a%c)if(b&1)ret=1LL*ret*a%c;return ret;}
10 int a, b, x, y, c, d, r;
11 int main(){
12     while(scanf("%d%d%d%d", &a, &b, &x, &y) != EOF){
13         assert(1 <= a && a <= 100000000);
14         assert(1 <= b && b <= 100000000);
15         assert(1 <= x && x <= a);
16         assert(1 <= y && y <= b);
17         assert((1LL * a * b) > 1);
18         if(a > b) swap(a, b), swap(x, y);
19         r = (a+1)/2;
20         c = max(x-1, a - x);
21         d = min(y, b - y + 1);
22         if (r < d && x - 1 != a - x) r = min(c, d);
23         if(a == b && (a & 1) && x == y && (x * 2 - 1 == a))
24                r = a / 2;
25         printf("%d\n", r);
26     }
27     return 0;
28 }
View Code

 

1004

 1 /*Author :usedrose  */
 2 /*Created Time :2015/7/24 9:38:58*/
 3 /*File Name :2.cpp*/
 4 #include <cstdio>
 5 #include <iostream>
 6 #include <algorithm>
 7 #include <sstream>
 8 #include <cstdlib>
 9 #include <cstring>
10 #include <climits>
11 #include <vector>
12 #include <string>
13 #include <ctime>
14 #include <cmath>
15 #include <deque>
16 #include <queue>
17 #include <stack>
18 #include <set>
19 #include <map>
20 #define INF 0x3f3f3f3f
21 #define eps 1e-8
22 #define pi acos(-1.0)
23 #define MAXN 200010
24 #define OK cout << "ok" << endl;
25 #define o(a) cout << #a << " = " << a << endl
26 #define o1(a,b) cout << #a << " = " << a << "  " << #b << " = " << b << endl
27 using namespace std;
28 typedef long long LL;
29 
30 
31 LL x[MAXN];
32 LL L[MAXN], R[MAXN];
33 LL disl[MAXN], disr[MAXN];
34 int n, k, len, T;
35 
36 int main()
37 {
38     //freopen("data.in","r",stdin);
39     //freopen("data.out","w",stdout);
40     cin.tie(0);
41     ios::sync_with_stdio(false);
42     cin >> T;
43     while (T--) {
44         LL m = 0, a, pos;
45         memset(disr, 0, sizeof(disr));
46         memset(disl, 0, sizeof(disl));
47         cin >> len >> n >> k;
48            for (int i = 0;i < n; ++ i) {
49             cin >> pos >> a;
50             for (int j = 0;j < a; ++ j) 
51                 x[++m] = pos;
52         }
53         int szl = 0, szr = 0;
54         for (int i = 1;i <= m; ++ i) 
55             if (x[i]*2 < len)
56                 L[szl++] = x[i];
57             else 
58                 R[szr++] = len - x[i];
59         sort(L, L + szl);
60         sort(R, R + szr);
61         for (int i = 0;i < szl; ++ i) 
62             disl[i+1] = (i + 1 <= k) ? L[i]: (disl[i - k + 1] + L[i]);
63         for (int i = 0;i < szr; ++ i)    
64             disr[i+1] = (i + 1 <= k) ? R[i]: (disr[i - k + 1] + R[i]);
65         
66         LL ans = 2*(disl[szl] + disr[szr]);
67 
68         //枚举从左右拿走大于等于n - k个的情况
69         //即中间剩下小于等于k个苹果的情况
70         for (int i = 0;i <= k && i <= szl; ++ i) {
71             int p1 = szl - i;
72             int p2 = max(0, szr - (k - i));
73             //o(disl[p1]);
74             //o(disr[p2]);
75             ans = min(ans, 2*(disl[p1] + disr[p2]) + len);
76         }
77         cout << ans << endl;
78 
79     }    
80     return 0;
81 }
View Code

 

1006

 1 /*Author :usedrose  */
 2 /*Created Time :2015/7/23 23:00:22*/
 3 /*File Name :2.cpp*/
 4 #include <cstdio>
 5 #include <iostream>
 6 #include <algorithm>
 7 #include <sstream>
 8 #include <cstdlib>
 9 #include <cstring>
10 #include <climits>
11 #include <vector>
12 #include <string>
13 #include <ctime>
14 #include <cmath>
15 #include <deque>
16 #include <queue>
17 #include <stack>
18 #include <set>
19 #include <map>
20 #define INF 0x3f3f3f3f
21 #define eps 1e-8
22 #define pi acos(-1.0)
23 #define MAXN 10
24 #define OK cout << "ok" << endl;
25 #define o(a) cout << #a << " = " << a << endl
26 #define o1(a,b) cout << #a << " = " << a << "  " << #b << " = " << b << endl
27 using namespace std;
28 typedef long long LL;
29 
30 int du[MAXN];
31 int G[MAXN][MAXN];
32 int ans, T;
33 int n, m;
34 
35 void dfs(int x, int y) 
36 {
37     if (x > n) ans++;
38     else if (y > n) {
39         if (du[x]) return;
40         dfs(x + 1, x + 2);
41     } else {
42         if (G[x][y]) {
43             du[x]++, du[y]++;
44             dfs(x, y + 1);
45             du[x] -=2, du[y] -= 2;
46             dfs(x, y + 1);
47             du[x]++, du[y]++;
48         }
49         else dfs(x, y + 1);
50     }
51 }
52 
53 int main()
54 {
55     //freopen("data.in","r",stdin);
56     //freopen("data.out","w",stdout);
57     cin.tie(0);
58     ios::sync_with_stdio(false);
59     cin >> T;
60     while (T--) {
61         ans = 0;
62         cin >> n >> m;
63         for (int i = 1;i <= n; ++ i)
64             for (int j = 0;j <= n; ++ j)
65                  G[i][j] = 0;
66         int x, y;
67         for (int i = 0;i < m; ++ i) {
68             cin >> x >> y;
69             G[x][y] = G[y][x] = 1;
70         }
71         dfs(1, 2);
72         cout << ans << endl;
73     }    
74     return 0;
75 }
View Code

 

1009

rabbit代码

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int n;
 5 int main(){
 6     while(~scanf("%d",&n)){
 7         if(n<4){
 8             puts("-1");
 9         }else{
10             if(n==4){
11                 puts("1 * 2\n5 + 3\n6 + 4");
12             }
13             if(n==5){
14                 puts("1 * 2\n6 * 3\n7 - 4\n8 / 5");
15             }
16             if(n==6){
17                 puts("1 + 2\n3 + 7");
18                 puts("4 + 5\n9 - 6");
19                 puts("8 + 10");
20             }
21             if(n==7){
22                 puts("1 + 2\n3 + 8\n9 / 4");
23                 puts("10 + 5\n11 + 6");
24                 puts("12 + 7");
25             }
26             if(n==8){
27                 for(int i=1;i<5;++i)printf("%d + %d\n",i,i+n-1);
28                 puts("12 / 5\n6 - 13\n14 * 7");
29             }
30             if(n==9){
31                 for(int i=1;i<6;++i)printf("%d + %d\n",i,i+n-1);
32                 puts("14 / 6\n15 + 7\n16 + 8");
33             }
34             if(n==10){
35                 for(int i=1;i<6;++i)printf("%d + %d\n",i,i+n-1);
36                 puts("15 / 6\n7 - 16\n8 + 17\n9 + 18");
37             }
38             if(n==11){
39                 puts("1 + 2\n3 + 4\n13 / 5\n14 + 12");
40                 for(int i=6;i<12;i+=2)printf("%d + %d\n%d - %d\n",i+9,i,i+10,i+1);
41             }
42             if(n>=12){
43                 if(n&1){
44                     for(int i=1;i<8;++i)printf("%d + %d\n",i,n+i-1);
45                     puts("8 + 9");
46                     printf("10 + %d\n",n+8);
47                     printf("%d / %d\n",n+7,11);
48                     printf("%d / %d\n",n+9,12);
49                     printf("%d * %d\n",n+10,n+11);
50                     for(int i=13;i<n;i+=2){
51                         printf("%d + %d\n%d - %d\n",n+i-1,i,n+i,i+1);
52                     }
53                 }else{
54                     for(int i=1;i<6;++i)printf("%d + %d\n",i,n+i-1);
55                     puts("6 + 7\n8 + 9");
56                     printf("%d + %d\n",n+6,n+7);
57                     printf("%d / %d\n",n+8,10);
58                     printf("%d / %d\n",n+5,11);
59                     printf("%d * %d\n",n+9,n+10);
60                     for(int i=12;i<n;i+=2){
61                         printf("%d + %d\n%d - %d\n",n+i-1,i,n+i,i+1);
62                     }
63                 }
64             }
65         }
66     }
67     return 0;
68 }
View Code

 

posted @ 2015-07-23 22:00  UsedRose  阅读(125)  评论(0编辑  收藏  举报