最近打的比较少。。。就只有这么点题解了。
You are given a following process.
There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.
The next line contain m integer numbers c1, c2, ..., cm (1 ≤ ci ≤ n) — column in which i-th square will appear.
Print one integer — the amount of points you will receive.
3 9
1 1 2 2 2 3 1 2 3
2
题意:类似俄罗斯方块,不过每次只降下一个1*1的方块。给出列数,还有每次方块降下所在的列,求能消除几列。
题解:算每列方块数然后求最小值。
1 #include<bits/stdc++.h> 2 #define clr(x) memset(x,0,sizeof(x)) 3 #define INF 0x3f3f3f3f 4 using namespace std; 5 const int N=1e3+10; 6 int a[N],n,m,d,minx; 7 int main() 8 { 9 scanf("%d%d",&n,&m); 10 for(int i=1;i<=m;i++) 11 { 12 scanf("%d",&d); 13 a[d]++; 14 } 15 minx=INF; 16 for(int i=1;i<=n;i++) 17 minx=min(minx,a[i]); 18 printf("%d ",minx); 19 return 0; 20 }
Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — ai during the i-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
The first line of the input contains two integer numbers n and k (1 ≤ k ≤ n ≤ 105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains n integer numbers a1, a2, ... an (1 ≤ ai ≤ 104) — the number of theorems lecturer tells during the i-th minute.
The third line of the input contains n integer numbers t1, t2, ... tn (0 ≤ ti ≤ 1) — type of Mishka's behavior at the i-th minute of the lecture.
Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
6 3
1 3 5 2 5 4
1 1 0 1 0 0
16
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
题意:第一行给出长度为n的价值序列,以及第二行可否获取的01序列,你可以最多把01序列里面连续k个置为1,问最多能获得多少价值。
题解:可获取的序列a[i]直接加入贡献,并置a[i]为0。然后求a[i]前缀和pre[i],找一个最大的pre[i]-pre[i-k]加入贡献,这样的贡献即为答案。
1 #include<bits/stdc++.h> 2 #define clr(x) memset(x,0,sizeof(x)) 3 #define INF 0x3f3f3f3f 4 using namespace std; 5 const int N=1e5+10; 6 int a[N],t,n,m,d,maxn,k,ans,now; 7 int main() 8 { 9 scanf("%d%d",&n,&k); 10 for(int i=1;i<=n;i++) 11 scanf("%d",a+i); 12 for(int i=1;i<=n;i++) 13 { 14 scanf("%d",&t); 15 if(t) 16 { 17 ans+=a[i]; 18 a[i]=0; 19 } 20 } 21 for(int i=1;i<=k && i<=n;i++) 22 now+=a[i]; 23 maxn=now; 24 for(int i=k+1;i<=n;i++) 25 { 26 now-=a[i-k]; 27 now+=a[i]; 28 maxn=max(maxn,now); 29 } 30 ans+=maxn; 31 printf("%d ",ans); 32 return 0; 33 34 }