Codeforces Round #248 (Div. 2)

题目在这儿http://codeforces.com/contest/433

A题:

A. Kitahara Haruki's Gift
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.

Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.

But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?

Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.

Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).

Sample test(s)
input
3
100 200 100
output
YES
input
4
100 100 100 200
output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
点这里看题

SB题,只需讨论n的奇偶和所有数(/100)的和的奇偶

B题:

B. Kuriyama Mirai's Stones
time limit per test 2 seconds
memory limit per test 256 megabytes
input standard input
output standard output
Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:

She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .
Let ui be the cost of the i-th cheapest stone (the cost that will be on the i-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .
For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.

Input
The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n integers: v1, v2, ..., vn (1 ≤ vi ≤ 109) — costs of the stones.

The third line contains an integer m (1 ≤ m ≤ 105) — the number of Kuriyama Mirai's questions. Then follow m lines, each line contains three integers type, l and r (1 ≤ l ≤ r ≤ n; 1 ≤ type ≤ 2), describing a question. If type equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.

Output
Print m lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.

Sample test(s)
input
6
6 4 2 7 2 7
3
2 3 6
1 3 4
1 1 6
output
24
9
28
input
4
5 5 2 3
10
1 2 4
2 1 4
1 1 1
2 1 4
2 1 2
1 1 1
1 3 3
1 1 3
1 4 4
1 2 2
output
10
15
5
15
5
5
2
12
3
5
Note
Please note that the answers to the questions may overflow 32-bit integer type.
点这里看题

sum[i]不多说

C题:

C. Ryouko's Memory Note
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output
Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what she hears on the notebook, and the notebook became her memory.

Though Ryouko is forgetful, she is also born with superb analyzing abilities. However, analyzing depends greatly on gathered information, in other words, memory. So she has to shuffle through her notebook whenever she needs to analyze, which is tough work.

Ryouko's notebook consists of n pages, numbered from 1 to n. To make life (and this problem) easier, we consider that to turn from page x to page y, |x - y| pages should be turned. During analyzing, Ryouko needs m pieces of information, the i-th piece of information is on page ai. Information must be read from the notebook in order, so the total number of pages that Ryouko needs to turn is .

Ryouko wants to decrease the number of pages that need to be turned. In order to achieve this, she can merge two pages of her notebook. If Ryouko merges page x to page y, she would copy all the information on page x to y (1 ≤ x, y ≤ n), and consequently, all elements in sequence a that was x would become y. Note that x can be equal to y, in which case no changes take place.

Please tell Ryouko the minimum number of pages that she needs to turn. Note she can apply the described operation at most once before the reading. Note that the answer can exceed 32-bit integers.

Input
The first line of input contains two integers n and m (1 ≤ n, m ≤ 105).

The next line contains m integers separated by spaces: a1, a2, ..., am (1 ≤ ai ≤ n).

Output
Print a single integer — the minimum number of pages Ryouko needs to turn.

Sample test(s)
input
4 6
1 2 3 4 3 2
output
3
input
10 5
9 4 3 8 8
output
6
Note
In the first sample, the optimal solution is to merge page 4 to 3, after merging sequence a becomes {1, 2, 3, 3, 3, 2}, so the number of pages Ryouko needs to turn is |1 - 2| + |2 - 3| + |3 - 3| + |3 - 3| + |3 - 2| = 3.

In the second sample, optimal solution is achieved by merging page 9 to 4.
点这里看题

统计每一页相邻的页面,并记录,枚举每一页被修改后的最小值即可

D题:

D. Nanami's Digital Board
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output
Nanami is an expert at playing games. This day, Nanami's good friend Hajime invited her to watch a game of baseball. Unwilling as she was, she followed him to the stadium. But Nanami had no interest in the game, so she looked around to see if there was something that might interest her. That's when she saw the digital board at one end of the stadium.

The digital board is n pixels in height and m pixels in width, every pixel is either light or dark. The pixels are described by its coordinate. The j-th pixel of the i-th line is pixel (i, j). The board displays messages by switching a combination of pixels to light, and the rest to dark. Nanami notices that the state of the pixels on the board changes from time to time. At certain times, certain pixels on the board may switch from light to dark, or from dark to light.

Nanami wonders, what is the area of the biggest light block such that a specific pixel is on its side. A light block is a sub-rectangle of the board, in which all pixels are light. Pixel (i, j) belongs to a side of sub-rectangle with (x1, y1) and (x2, y2) as its upper-left and lower-right vertex if and only if it satisfies the logical condition:

((i = x1 or i = x2) and (y1 ≤ j ≤ y2)) or ((j = y1 or j = y2) and (x1 ≤ i ≤ x2)).
Nanami has all the history of changing pixels, also she has some questions of the described type, can you answer them?

Input
The first line contains three space-separated integers n, m and q (1 ≤ n, m, q ≤ 1000) — the height and width of the digital board, and the number of operations.

Then follow n lines, each line containing m space-separated integers. The j-th integer of the i-th line is ai, j — the initial state of pixel (i, j).

If ai, j = 0, pixel (i, j) is initially dark.
If ai, j = 1, pixel (i, j) is initially light.
Then follow q lines, each line containing three space-separated integers op, x, and y (1 ≤ op ≤ 2; 1 ≤ x ≤ n; 1 ≤ y ≤ m), describing an operation.

If op = 1, the pixel at (x, y) changes its state (from light to dark or from dark to light).
If op = 2, Nanami queries the biggest light block with pixel (x, y) on its side.
Output
For each query, print a single line containing one integer — the answer to Nanami's query.

Sample test(s)
input
3 4 5
0 1 1 0
1 0 0 1
0 1 1 0
2 2 2
2 1 2
1 2 2
1 2 3
2 2 2
output
0
2
6
input
3 3 4
1 1 1
1 1 1
1 1 1
2 2 2
1 2 2
2 1 1
2 2 1
output
6
3
3
Note
Consider the first sample.

The first query specifies pixel (2, 2), which is dark itself, so there are no valid light blocks, thus the answer is 0.

The second query specifies pixel (1, 2). The biggest light block is the block with (1, 2) as its upper-left vertex and (1, 3) as its lower-right vertex.

The last query specifies pixel (2, 2), which became light in the third operation. The biggest light block is the block with (1, 2) as its upper-left vertex and (3, 3) as its lower-right vertex.
点这里看题

用L(i,j),R(i,j),U(i,j),D(i,j)分别表示第i行到j所能形成的最长边、从m到j的最长边,第j列中从1到i的最长边,从n到j的最长边

E题:

E. Tachibana Kanade's Tofu
time limit per test 5 seconds
memory limit per test 512 megabytes
input standard input
output standard output
Tachibana Kanade likes Mapo Tofu very much. One day, the canteen cooked all kinds of tofu to sell, but not all tofu is Mapo Tofu, only those spicy enough can be called Mapo Tofu.

Each piece of tofu in the canteen is given a m-based number, all numbers are in the range [l, r] (l and r being m-based numbers), and for every m-based integer in the range [l, r], there exists a piece of tofu with that number.

To judge what tofu is Mapo Tofu, Tachibana Kanade chose n m-based number strings, and assigned a value to each string. If a string appears in the number of a tofu, the value of the string will be added to the value of that tofu. If a string appears multiple times, then the value is also added that many times. Initially the value of each tofu is zero.

Tachibana Kanade considers tofu with values no more than k to be Mapo Tofu. So now Tachibana Kanade wants to know, how many pieces of tofu are Mapo Tofu?

Input
The first line contains three integers n, m and k (1 ≤ n ≤ 200; 2 ≤ m ≤ 20; 1 ≤ k ≤ 500). Where n denotes the number of strings, m denotes the base used, and k denotes the limit of the value for Mapo Tofu.

The second line represents the number l. The first integer in the line is len (1 ≤ len ≤ 200), describing the length (number of digits in base m) of l. Then follow len integers a1, a2, ..., alen (0 ≤ ai < m; a1 > 0) separated by spaces, representing the digits of l, with a1 being the highest digit and alen being the lowest digit.

The third line represents the number r in the same format as l. It is guaranteed that 1 ≤ l ≤ r.

Then follow n lines, each line describing a number string. The i-th line contains the i-th number string and vi — the value of the i-th string (1 ≤ vi ≤ 200). All number strings are described in almost the same format as l, the only difference is number strings may contain necessary leading zeros (see the first example). The sum of the lengths of all number strings does not exceed 200.

Output
Output the number of pieces of Mapo Tofu modulo 1000000007 (109 + 7). The answer should be a decimal integer.

Sample test(s)
input
2 10 1
1 1
3 1 0 0
1 1 1
1 0 1
output
97
input
2 10 12
2 5 9
6 6 3 5 4 9 7
2 0 6 1
3 6 7 2 1
output
635439
input
4 2 6
6 1 0 1 1 1 0
6 1 1 0 1 0 0
1 1 2
3 0 1 0 5
4 0 1 1 0 4
3 1 0 1 2
output
2
Note
In the first sample, 10, 11 and 100 are the only three decimal numbers in [1, 100] with a value greater than 1. Here the value of 1 is 1 but not 2, since numbers cannot contain leading zeros and thus cannot be written as "01".

In the second sample, no numbers in the given interval have a value greater than 12.

In the third sample, 110000 and 110001 are the only two binary numbers in the given interval with a value no greater than 6.
点这里看题

不会T_T...先挖坑。。

  1 #include<cmath>
  2 #include<queue>
  3 #include<vector>
  4 #include<cstdio>
  5 #include<cstring>
  6 #include<cstdlib>
  7 #include<iostream>
  8 #include<algorithm>
  9 using namespace std;
 10 const int inf = 214748367;
 11 #define For(i,n) for(int i=1;i<=n;++i)
 12 #define Rep(i,l,r) for(int i=l;i<=r;++i)
 13 bool flag = false;
 14 int n,foods,ans;
 15 
 16 int main(){
 17     scanf("%d",&n);
 18     For(i,n){
 19         scanf("%d",&foods);
 20         if(foods==100) flag = true;
 21         ans+=foods/100;
 22     }
 23     if(ans%2) puts("NO");
 24     else{
 25         if(flag)     puts("YES");
 26         else if(n%2) puts("NO");
 27         else         puts("YES");
 28     }
 29     return 0;
 30 }
 31 -----------------------------------以上是A题----------------------------------
 32 #include<cmath>
 33 #include<queue>
 34 #include<vector>
 35 #include<cstdio>
 36 #include<cstring>
 37 #include<cstdlib>
 38 #include<iostream>
 39 #include<algorithm>
 40 using namespace std;
 41 const int N = (1e5)+10;
 42 #define For(i,n) for(int i=1;i<=n;++i)
 43 #define Rep(i,l,r) for(int i=l;i<=r;++i)
 44 
 45 int m,n,a[N],op,l,r;
 46 long long ssum[N],sum[N];
 47 int main(){
 48     scanf("%d",&n);
 49     For(i,n){
 50         scanf("%d",&a[i]);
 51         sum[i] = sum[i-1]+a[i];
 52     }
 53     sort(a+1,a+n+1);
 54     For(i,n) ssum[i] = ssum[i-1]+a[i];
 55     scanf("%d",&m);
 56     For(i,m){
 57         scanf("%d%d%d",&op,&l,&r);
 58         if(op==1) cout<<sum[r]-sum[l-1]<<endl;
 59         else      cout<<ssum[r]-ssum[l-1]<<endl;
 60     }
 61     return 0;
 62 }
 63 ---------------------------------以上是B题----------------------------------
 64 #include<cmath>
 65 #include<queue>
 66 #include<vector>
 67 #include<cstdio>
 68 #include<cstring>
 69 #include<cstdlib>
 70 #include<iostream>
 71 #include<algorithm>
 72 using namespace std;
 73 const int N = (1e5)+10;
 74 #define pb push_back
 75 #define For(i,n) for(int i=1;i<=n;++i)
 76 #define Rep(i,l,r) for(int i=l;i<=r;++i)
 77 #define forecho(it,a) for(vector<int>::iterator it = a.begin();it!=a.end();++i)
 78 vector<int> s[N];
 79 int a[N],n,m;
 80 long long ans,red;
 81 
 82 int main(){
 83     scanf("%d%d",&n,&m);
 84     For(i,m){
 85         scanf("%d",&a[i]);      
 86         if(i==1||a[i]==a[i-1]) continue;
 87         s[a[i]].pb(a[i-1]);
 88         s[a[i-1]].pb(a[i]);
 89         ans+=abs(a[i]-a[i-1]);
 90     }
 91     For(i,n){
 92         if(s[i].empty()) continue;
 93         sort(s[i].begin(),s[i].end());
 94         int mid = s[i][s[i].size()/2];
 95         long long ans1,ans2;ans1=ans2=0;
 96         Rep(j,0,s[i].size()-1){
 97             ans1+=abs(s[i][j]-mid);
 98             ans2+=abs(s[i][j]-i);
 99         }
100         if(ans2-ans1>red) red = ans2-ans1;
101     }
102     cout<<ans-red<<endl;
103     return 0;
104 }
105 ---------------------------------以上是C题----------------------------------
106 #include <queue>
107 #include <cstdio>
108 #include <vector>
109 #include <cstdlib>
110 #include <cstring>
111 #include <iostream>
112 #include <algorithm>
113 using namespace std;
114 #define ll long long
115 #define oo (1 << 30)
116 #define For(i,n) for(int i=1;i<=n;i++)
117 #define Rep(i,l,r) for(int i=l;i<=r;i++)
118 #define Down(i,r,l) for(int i=r;i>=l;i--)
119 const int maxn = 1010;
120 int a[maxn][maxn], o, x, y;
121 int n, m, q, L[maxn][maxn], R[maxn][maxn], U[maxn][maxn], D[maxn][maxn];
122 
123 void init(){
124     scanf("%d %d %d", &n, &m, &q);
125     For(i,n)
126         For(j,m)
127             scanf("%d", a[i] + j);
128     For(i,n){
129         For(j,m)
130             L[i][j] = a[i][j] ? L[i][j - 1] + 1 : 0;
131         Down(j,m,1)
132             R[i][j] = a[i][j] ? R[i][j + 1] + 1 : 0;
133     }
134     For(j,m){
135         For(i,n)
136             U[i][j] = a[i][j] ? U[i - 1][j] + 1 : 0;
137         Down(i,n,1)
138             D[i][j] = a[i][j] ? D[i + 1][j] + 1 : 0;
139     }
140 }
141 
142 void update(){
143     a[x][y] ^= 1;
144     For(j,m)
145         L[x][j] = a[x][j] ? L[x][j - 1] + 1 : 0;
146     Down(j,m,1)
147         R[x][j] = a[x][j] ? R[x][j + 1] + 1 : 0; 
148     For(i,n)
149         U[i][y] = a[i][y] ? U[i - 1][y] + 1 : 0;
150     Down(i,n,1)
151         D[i][y] = a[i][y] ? D[i + 1][y] + 1 : 0;
152 }
153 
154 void query(){                                       
155     if (!a[x][y]) printf("0
");else{
156         int up = oo, down = oo, ans = 0;
157         Down(j,y,1){
158             up = min(U[x][j], up), down = min(D[x][j], down);
159             ans = max(ans, (up + down - 1) * (y - j + 1));
160         }
161         up = oo, down = oo;
162         Rep(j,y,m){
163             up = min(U[x][j], up), down = min(D[x][j], down);
164             ans = max(ans, (up + down - 1) * (j - y + 1));
165         }
166         int left = oo, right = oo;
167         Down(i,x,1){
168             left = min(left, L[i][y]), right = min(right, R[i][y]);
169             ans = max(ans, (left + right - 1) * (x - i + 1));
170         }       
171         left = oo, right = oo;
172         Rep(i,x,n){
173             left = min(left, L[i][y]), right = min(right, R[i][y]);
174             ans = max(ans, (left + right - 1) * (i - x + 1));
175         }       
176         printf("%d
", ans);
177     }
178 }
179 
180 int main(){
181     init();
182     For(i,q){
183         scanf("%d %d %d", &o, &x, &y);
184         if (o == 1) update(); 
185         else        query();
186     }
187     return 0;
188 }
189 ---------------------------------以上是D题------------------------------------
190 //挖坑T_T...
191 ---------------------------------以上是E题------------------------------------
所有题代码

 

原文地址:https://www.cnblogs.com/zjdx1998/p/3757143.html