12.28
On this day make up the title on the last two CF, after writing a bunch dp template, and finally hit a AtCoder, feeling pretty good, but also the structure of metaphysics in order to compare the title over it.
A.Table Tennis Training
The meaning of problems: there are 2n athletes, n tables. In the x-table will win into the x-1, will enter the input x + 1, in addition to the people on the table 1 and n, there are two very strong human cytomegalovirus are on the table A and B , free to control the winning or losing, they at least need to ask how much the wheel in order to play on a table.
Ideas: If AB already adjacent They must be put to one side to push (or 1 N) can, if the difference exactly 2, it can be a win into the middle of a transmission. Thus a difference is first determined parity, an even number Direct / 2 on the line, if it is an odd number, to see who is closer to the edge, let him aside, and then a round edge, the difference is an even number, then close again . Note open LL.
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mid ((l+r)>>1)
const int M=1e5+20,P=1e9+7;
struct Task{
LL n,a,b;
void init(){
scanf("%lld%lld%lld",&n,&a,&b);
}
void run(){
init();
if ((a-b)%2==0)
printf("%lld\n",abs(b-a)/2);
else
printf("%lld\n",min(a-1,n-b)+(abs(a-b)+1)/2);
}
}t;
int main(){
t.run();
return 0;
}
B.Voting Judges
The meaning of problems: there are N problem, there is a beginning of each question a [i] points. There are M referee, everyone will just choose a V issues that scores +1. Finally, choose the highest score of the P issues elected, if the same score, then the chief will be randomly ranked. Now ask how many questions are likely to be elected?
Thinking: amply meets bipartite nature (of course, may be directly scan again). First by a [i] from small to large, we judge to consider whether the i-th issue to be chosen. Votes may be equivalent to, to add MV, but each increase in M most problems, added after the i-th ranked question to> = N-P + 1. Thus it can be greedy, the i-th first issue as many votes affirmative, i.e. M is obtained, then let P-1 obtained in front of each problem M, i.e. n-p + 2 to n, then again, since the i-th problems increased M, then 1 to i-1 of these issues can also get M, anyway, after the addition of yet no more than the i-th issue. This has been divided out (1 + P-1 + i -1) * M votes. After remaining i + 1-np these problems (with k expressed), they can get votes, but the votes obtained no more than (a [i] + Ma [ k]), thus ensuring that when the final ranking, intermediate question does not exceed the i-th question, this problem is at least the i-th row in the p-position. And that intermediate may be treated with the prefix. You can find half the cut-off point, you can also scan directly to On. Anyway, judgments are O (1) is.
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mid ((l+r)>>1)
const int M=3e5+20,P=1e9+7;
struct Task{
LL n,m,v,p,a[M];
LL sum[M];
void init(){
scanf("%lld%lld%lld%lld",&n,&m,&v,&p);
for(int i=1;i<=n;++i)
scanf("%lld",&a[i]);
}
void run(){
init();
sort(a+1,a+n+1);
for(int i=1;i<=n;++i)
sum[i]=sum[i-1]+a[i];
LL ans=n-p;
while(ans>=1){
if(a[ans]+m<a[n-p+1])
break;
if(1LL*(ans+p-1)*m+1LL*(n-p+1-(ans+1)+1)*(a[ans]+m)-(sum[n-p+1]-sum[ans])>=1LL*v*m)
--ans;
else
break;
}
printf("%lld\n",n-ans);
}
}t;
int main(){
t.run();
return 0;
}
C.Domino Quality
The meaning of problems: there are 2 * 1 block pile may be placed horizontally or upright in an n × n grid. After the requirement to put the same number of squares each row and vertical column appeared.
Ideas: configuration problem. 2 does not exist, you can get out of 34567, 3 if they had if they had 2,4567 3. So then you can use these to do the 6k + 3, 3 directly to spell.
For 6k, 6k + 4,6k + 5, the k first fight 6 × 6, before adding a 4 × 4 or 5 × 5.
Of 6k + 1,6k + 2, first fight the k-1 6 × 6, before adding one or both of the 7 × 7 to 4 × 4.
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mid ((l+r)>>1)
const int M=1e3+20,P=1e9+7;
struct Task{
int n;
char s[M][M];
void init(){
scanf("%d",&n);
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
s[i][j]='.';
}
void run(){
init();
if (n==2){
cout<<-1<<endl;
return ;
}
if (n%3==0){
for(int i=1;i<=n/3;++i){
int ca=3*(i-1);
s[ca+1][ca+1]=s[ca+1][ca+2]='a';
s[ca+1][ca+3]=s[ca+2][ca+3]='b';
s[ca+2][ca+1]=s[ca+3][ca+1]='c';
s[ca+3][ca+2]=s[ca+3][ca+3]='d';
}
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j)
putchar(s[i][j]);
putchar('\n');
}
return;
}
if (n%6==0||n%6==4||n%6==5){
for(int i=1;i<=n/6;++i){
int ca=6*(i-1);
s[ca+1][ca+1]=s[ca+2][ca+1]='a';
s[ca+1][ca+4]=s[ca+2][ca+4]='b';
s[ca+1][ca+5]=s[ca+1][ca+6]='c';
s[ca+2][ca+5]=s[ca+2][ca+6]='d';
s[ca+3][ca+2]=s[ca+4][ca+2]='e';
s[ca+3][ca+3]=s[ca+3][ca+4]='f';
s[ca+3][ca+5]=s[ca+4][ca+5]='g';
s[ca+4][ca+3]=s[ca+4][ca+4]='h';
s[ca+5][ca+1]=s[ca+5][ca+2]='i';
s[ca+6][ca+1]=s[ca+6][ca+2]='j';
s[ca+5][ca+3]=s[ca+6][ca+3]='k';
s[ca+5][ca+6]=s[ca+6][ca+6]='l';
}
int ca=6*(n/6);
if (n%6==4){
s[ca+1][ca+1]=s[ca+1][ca+2]='a';
s[ca+2][ca+1]=s[ca+2][ca+2]='b';
s[ca+1][ca+3]=s[ca+2][ca+3]='c';
s[ca+1][ca+4]=s[ca+2][ca+4]='d';
s[ca+3][ca+1]=s[ca+4][ca+1]='e';
s[ca+3][ca+2]=s[ca+4][ca+2]='f';
s[ca+3][ca+3]=s[ca+3][ca+4]='g';
s[ca+4][ca+3]=s[ca+4][ca+4]='h';
}
if (n%6==5){
s[ca+1][ca+1]=s[ca+2][ca+1]='a';
s[ca+3][ca+1]=s[ca+4][ca+1]='b';
s[ca+5][ca+1]=s[ca+5][ca+2]='c';
s[ca+5][ca+3]=s[ca+5][ca+4]='d';
s[ca+5][ca+5]=s[ca+4][ca+5]='e';
s[ca+3][ca+5]=s[ca+2][ca+5]='f';
s[ca+1][ca+5]=s[ca+1][ca+4]='g';
s[ca+1][ca+3]=s[ca+1][ca+2]='h';
s[ca+2][ca+2]=s[ca+2][ca+3]='i';
s[ca+3][ca+4]=s[ca+4][ca+4]='j';
}
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j)
putchar(s[i][j]);
putchar('\n');
}
return;
}
if (n%6==1||n%6==2){
for(int i=1;i<=n/6-1;++i){
int ca=6*(i-1);
s[ca+1][ca+1]=s[ca+2][ca+1]='a';
s[ca+1][ca+4]=s[ca+2][ca+4]='b';
s[ca+1][ca+5]=s[ca+1][ca+6]='c';
s[ca+2][ca+5]=s[ca+2][ca+6]='d';
s[ca+3][ca+2]=s[ca+4][ca+2]='e';
s[ca+3][ca+3]=s[ca+3][ca+4]='f';
s[ca+3][ca+5]=s[ca+4][ca+5]='g';
s[ca+4][ca+3]=s[ca+4][ca+4]='h';
s[ca+5][ca+1]=s[ca+5][ca+2]='i';
s[ca+6][ca+1]=s[ca+6][ca+2]='j';
s[ca+5][ca+3]=s[ca+6][ca+3]='k';
s[ca+5][ca+6]=s[ca+6][ca+6]='l';
}
int ca=6*(n/6-1);
if (n%6==1){
s[ca+1][ca+1]=s[ca+1][ca+2]='a';
s[ca+1][ca+3]=s[ca+1][ca+4]='b';
s[ca+1][ca+6]=s[ca+2][ca+6]='c';
s[ca+2][ca+1]=s[ca+3][ca+1]='d';
s[ca+4][ca+1]=s[ca+5][ca+1]='e';
s[ca+2][ca+2]=s[ca+2][ca+3]='f';
s[ca+3][ca+3]=s[ca+3][ca+4]='g';
s[ca+4][ca+5]=s[ca+5][ca+5]='h';
s[ca+6][ca+5]=s[ca+6][ca+6]='i';
s[ca+6][ca+2]=s[ca+7][ca+2]='j';
s[ca+7][ca+4]=s[ca+7][ca+5]='k';
s[ca+7][ca+6]=s[ca+7][ca+7]='l';
s[ca+3][ca+7]=s[ca+4][ca+7]='m';
s[ca+5][ca+7]=s[ca+6][ca+7]='n';
}
if (n%6==2){
s[ca+1][ca+1]=s[ca+1][ca+2]='a';
s[ca+2][ca+1]=s[ca+2][ca+2]='b';
s[ca+1][ca+3]=s[ca+2][ca+3]='c';
s[ca+1][ca+4]=s[ca+2][ca+4]='d';
s[ca+3][ca+1]=s[ca+4][ca+1]='e';
s[ca+3][ca+2]=s[ca+4][ca+2]='f';
s[ca+3][ca+3]=s[ca+3][ca+4]='g';
s[ca+4][ca+3]=s[ca+4][ca+4]='h';
ca+=4;
s[ca+1][ca+1]=s[ca+1][ca+2]='a';
s[ca+2][ca+1]=s[ca+2][ca+2]='b';
s[ca+1][ca+3]=s[ca+2][ca+3]='c';
s[ca+1][ca+4]=s[ca+2][ca+4]='d';
s[ca+3][ca+1]=s[ca+4][ca+1]='e';
s[ca+3][ca+2]=s[ca+4][ca+2]='f';
s[ca+3][ca+3]=s[ca+3][ca+4]='g';
s[ca+4][ca+3]=s[ca+4][ca+4]='h';
}
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j)
putchar(s[i][j]);
putchar('\n');
}
}
}
}t;
int main(){
t.run();
return 0;
}
D.Problem Scores
Back to fix