Jackiesteed

www.github.com/jackiesteed

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

题目传送门

A:

View Code
 1 #include <iostream>
2 #include <fstream>
3 #include <algorithm>
4
5 using namespace std;
6
7 typedef pair<int, int> pii;
8
9 pii array[1100];
10 int n, k;
11
12 int main()
13 {
14 // freopen("input.txt", "r", stdin);
15
16 scanf("%d %d", &n, &k);
17 k *= 2;
18 for(int i = 0; i < n; i++)
19 {
20 scanf("%d %d", &array[i].first, &array[i].second);
21 array[i].first *= 2, array[i].second *= 2;
22 }
23
24 sort(array, array + n);
25 int ans = 2;
26 for(int i = 0; i < n - 1; i++)
27 {
28 int len = array[i].first + array[i].second / 2;
29 len = array[i + 1].first - array[i + 1].second / 2 - len;
30 if(len == k)
31 ans++;
32 else if(len > k)
33 ans += 2;
34 }
35 printf("%d\n", ans);
36
37 return 0;
38 }

B:

View Code
 1 #include <iostream>
2 #include <fstream>
3 #include <algorithm>
4 #include <cstring>
5 #include <cstdlib>
6 #include <cmath>
7 #include <climits>
8
9 using namespace std;
10
11 typedef long long LL;
12
13 int main()
14 {
15 // freopen("input.txt", "r", stdin);
16 int T;
17 scanf("%d", &T);
18
19 while(T--)
20 {
21 LL n, m, x1, y1, x2, y2;
22 scanf("%I64d %I64d %I64d %I64d %I64d %I64d", &n, &m, &x1, &y1, &x2, &y2);
23
24 LL l = llabs(y1 - y2);
25 LL h =llabs(x1 - x2);
26 LL ans = 2 * (n - h) * (m - l);
27 LL tmp = max(0LL, 2 * (n - h) - n) * max(0LL, 2 * (m - l) - m);
28 ans -= tmp;
29 ans = n * m - ans;
30 printf("%I64d\n", ans);
31
32 }
33
34 return 0;
35 }

C:

从0到 ((1 << n) - 1)(n > 1)的所有数相异或的结果为0, 那么就可以分部搞了..

View Code
 1 #include <iostream>
2 #include <fstream>
3 #include <cstring>
4 #include <cmath>
5 #include <climits>
6 #include <cstdlib>
7 #include <cstdlib>
8 #include <climits>
9
10 using namespace std;
11
12 typedef long long LL;
13
14 int N;
15
16 LL get(LL x)
17 {
18 LL ans = 0;
19 LL base = 1;
20 while(base <= x)
21 {
22 base <<= 1;
23 }
24 while(x)
25 {
26 if(x == 2)
27 {
28 ans += 3;
29 break;
30 }
31 if(x == 1)
32 {
33 ans++;
34 break;
35 }
36 while(x < base)
37 {
38 base >>= 1;
39 }
40 if((x + 1) == (base << 1))
41 {
42 break;
43 }
44 LL tmp = x % base;
45 ans += base * ((tmp + 1) % 2);
46 x = tmp;
47 }
48 return ans;
49 }
50
51 inline LL calc(LL x, LL m)
52 {
53 return get(x - 1) ^ get(x + m - 1);
54 }
55
56 int main()
57 {
58 // freopen("input.txt", "r", stdin);
59
60 scanf("%d", &N);
61
62 LL ans = 0;
63 LL x, m;
64 for(int i = 0; i < N; i++)
65 {
66 scanf("%I64d %I64d", &x, &m);
67 ans ^= calc(x, m);
68 }
69 if(ans == 0)
70 {
71 puts("bolik");
72 }
73 else
74 {
75 puts("tolik");
76 }
77
78 return 0;
79 }

D:

RMQ, 时间界感觉卡得挺紧的~.

View Code
  1 #include <iostream>
2 #include <fstream>
3 #include <algorithm>
4 #include <cstring>
5 #include <cstdlib>
6 #include <climits>
7 #include <cmath>
8
9 using namespace std;
10
11 typedef long long LL;
12
13 int dp[1010][1010][10];
14 int mat[1010][1010];
15 LL row[1010][1010];
16 LL col[1010][1010];
17
18 int N, M;
19 int a, b;
20
21 typedef struct node
22 {
23 int x, y;
24 LL val;
25 }node;
26 node q[1000010];
27 int record[1000010];
28 void mkrmq(int dp[1010][10], int array[1010], int L)
29 {
30 for(int i = 1; i <= L; i++)
31 dp[i][0] = array[i];
32
33 for(int j = 1; (1 << j) <= L; j++)
34 {
35 for(int i = 1; i + (1 << j) - 1 <= L; i++)
36 {
37 dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
38 }
39 }
40 }
41 int rmq(int dp[1010][10], int s, int t)
42 {
43 int k = (log(double(t - s + 1)) / log(2.0));
44 return min(dp[s][k], dp[t - (1 << k) + 1][k]);
45 }
46
47 LL sum(int x, int y)
48 {
49 return col[x + a - 1][y + b - 1] + col[x - 1][y - 1] -
50 col[x - 1][y + b - 1] - col[x + a - 1][y - 1];
51 }
52 inline bool cmp(const node& n1, const node& n2)
53 {
54 if(n1.val != n2.val)
55 return n1.val < n2.val;
56 if(n1.x != n2.x)
57 return n1.x < n2.x;
58 return n1.y < n2.y;
59 }
60 void work()
61 {
62 for(int i = 1; i <= N; i++)
63 {
64 mkrmq(dp[i], mat[i], M);
65 }
66 for(int i = 1; i <= N; i++)
67 {
68 for(int j =1; j <= M; j++)
69 {
70 row[i][j] = row[i][j - 1] + mat[i][j];
71 col[i][j] = col[i - 1][j] + row[i][j];
72 }
73 }
74
75 int array[1010];
76 int dp1[1010][10];
77 int cnt = 0;
78 for(int i = 1; i + b - 1 <= M; i++)//col
79 {
80 for(int j = 1; j <= N; j++)
81 {
82 array[j] = rmq(dp[j], i, i + b - 1);
83 // printf("%d ", array[j]);
84 }
85 // puts("");
86 mkrmq(dp1, array, N);
87 for(int j = 1; j + a - 1 <= N; j++)
88 {
89 q[cnt].x = j, q[cnt].y = i;
90 q[cnt].val = sum(j, i) - (LL)rmq(dp1, j, j + a - 1) * LL(a * b);
91 // printf("%d ===\n", rmq(dp1, j, j + a - 1));
92
93 // printf("%d %d %I64d\n", q[cnt].x, q[cnt].y, q[cnt].val);
94
95 cnt++;
96 }
97 }
98
99 sort(q, q + cnt, cmp);
100 int ans = 0;
101 for(int i = 0; i < cnt; i++)
102 {
103 int x = q[i].x, y = q[i].y;
104 if(-1 != mat[x][y])
105 {
106 record[ans++] = i;
107 for(int i = max(1, x - a + 1); i < x + a; i++)
108 {
109 for(int j = max(1, y - b + 1); j < y + b; j++)
110 {
111 mat[i][j] = -1;
112 }
113 }
114 }
115 }
116 printf("%d\n", ans);
117 for(int i = 0; i < ans; i++)
118 {
119 int z = record[i];
120 printf("%d %d %I64d\n", q[z].x, q[z].y, q[z].val);
121 }
122 }
123
124 int main()
125 {
126
127 // freopen("input.txt", "r", stdin);
128
129 scanf("%d %d", &N, &M);
130 scanf("%d %d", &a, &b);
131
132 for(int i = 1; i <= N; i++)
133 {
134 for(int j = 1; j <= M; j++)
135 {
136 scanf("%d", &mat[i][j]);
137 }
138 }
139 work();
140
141 return 0;
142 }

E:

╮(╯_╰)╭ ~~~

posted on 2011-08-06 01:27  Jackiesteed  阅读(243)  评论(0编辑  收藏  举报