Educational Codeforces Round 41 (Rated for Div. 2)

好久不见. 提交于 2020-02-14 20:49:37

 

这个D可以参考这个B的思路

A. Tetris
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

Print one integer — the amount of points you will receive.

Example
input
Copy
3 91 1 2 2 2 3 1 2 3
output
2
Note

In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2 3 1], and after removing one row will be [1 2 0]).

After the appearing of 9-th square counts will be [2 3 1], and after removing one row it will look like [1 2 0].

So the answer will be equal to 2.

俄罗斯方块,别看它瞎逼逼,直接选择那个最小的吧

#include <bits/stdc++.h>
using namespace std;
const int N=1005;
int num[N];
int main()
{
    int n,m;
    cin>>n>>m;
    int ans=N;
    for(int i=0,x;i<m;i++)
        cin>>x,num[x]++;
    for(int i=1;i<=n;i++)ans=min(ans,num[i]);
    cout<<ans;
}
B. Lecture Sleep
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

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.

Example
input
Copy
6 31 3 5 2 5 41 1 0 1 0 0
output
16
Note

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.

就是一堂上为0的时候你是睡着的,你可以使用一个技能,这段时间醒着的,尽量让自己听到更多的知识,醒的时间为k,也就是可以任选一段(i,i+k-1)

所以前缀后缀和算一下,枚举区段,我这个f[i]为0怎么不前缀和啊,怕是个傻子,wa到明年了

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
ll a[N],f[N],b[N],c[N];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    for(int i=1; i<=n; i++)
        cin>>f[i];
    for(int i=1; i<=n; i++)
        if(f[i])b[i]=b[i-1]+a[i];
        else b[i]=b[i-1];
    for(int i=n; i>0; i--)
        if(f[i])c[i]=c[i+1]+a[i];
        else c[i]=c[i+1];
    ll s=0;
    for(int i=1; i<=k; i++)s+=a[i];
    ll ans=0;
    for(int i=k; i<=n; i++)
        ans=max(b[i-k]+s+c[i+1],ans),s=s-a[i-k+1]+a[i+1];
    cout<<ans;
}
C. Chessboard
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4pieces, each of size n by nn is always odd. And what's even worse, some squares were of wrong color. j-th square of the i-th row of k-th piece of the board has color ak, i, j1 being black and 0 being white.

Now Magnus wants to change color of some squares in such a way that he recolors minimum number of squares and obtained pieces form a valid chessboard. Every square has its color different to each of the neightbouring by side squares in a valid board. Its size should be 2nby 2n. You are allowed to move pieces but not allowed to rotate or flip them.

Input

The first line contains odd integer n (1 ≤ n ≤ 100) — the size of all pieces of the board.

Then 4 segments follow, each describes one piece of the board. Each consists of n lines of n characters; j-th one of i-th line is equal to 1 if the square is black initially and 0 otherwise. Segments are separated by an empty line.

Output

Print one number — minimum number of squares Magnus should recolor to be able to obtain a valid chessboard.

Examples
input
Copy
10010
output
1
input
Copy
3101010101101000101010101011010101010
output
2

这个题目简单啊,因为是奇数的,所以只存在1开头的,还有0开头的两种块,暴力统计下

#include <bits/stdc++.h>
using namespace std;
const int N=105;
string s1[N],s2[N],s3[N],s4[N];
int a[N][N],b[N][N];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>s1[i];
    cin.get();
    for(int i=0;i<n;i++)
        cin>>s2[i];
    cin.get();
    for(int i=0;i<n;i++)
        cin>>s3[i];
    cin.get();
    for(int i=0;i<n;i++)
        cin>>s4[i];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        a[i][j]=(i+j)%2==0?1:0,b[i][j]=(i+j)%2?1:0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        a[i][j]+=48,b[i][j]+=48;
    int ans=1e9;
    int f=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            f+=(s1[i][j]!=a[i][j])+(s2[i][j]!=a[i][j])+(s3[i][j]!=b[i][j])+(s4[i][j]!=b[i][j]);
    ans=min(ans,f);
    f=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            f+=(s1[i][j]!=a[i][j])+(s2[i][j]!=b[i][j])+(s3[i][j]!=a[i][j])+(s4[i][j]!=b[i][j]);
    ans=min(ans,f);
    f=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            f+=(s1[i][j]!=a[i][j])+(s2[i][j]!=b[i][j])+(s3[i][j]!=b[i][j])+(s4[i][j]!=a[i][j]);
    ans=min(ans,f);
    f=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            f+=(s1[i][j]!=b[i][j])+(s2[i][j]!=a[i][j])+(s3[i][j]!=a[i][j])+(s4[i][j]!=b[i][j]);
    ans=min(ans,f);
    f=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            f+=(s1[i][j]!=b[i][j])+(s2[i][j]!=a[i][j])+(s3[i][j]!=b[i][j])+(s4[i][j]!=a[i][j]);
    ans=min(ans,f);
    f=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            f+=(s1[i][j]!=b[i][j])+(s2[i][j]!=b[i][j])+(s3[i][j]!=a[i][j])+(s4[i][j]!=a[i][j]);
    ans=min(ans,f);
    cout<<ans;
}

可以二维的string,for去枚举,这样就可以少写点代码了,不过本来就是复制粘贴

D. Pair Of Lines
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.

You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?

Input

The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given.

Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.

Output

If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.

Examples
input
Copy
50 00 11 11 -12 2
output
YES
input
Copy
50 01 02 11 12 3
output
NO
Note

In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.

确定直线啊,把三点确定一条直线,也就是可以 1 2和其他,1 3和其他,2 3和其他,然后再对当前组判断就好了,被叉了,所有的点都要判断共线

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll x[N],y[N];
vector<int>V;
int n,d,f;
bool gx(int a,int b,int c)
{
    return (x[b]-x[a])*(y[c]-y[b])==(x[c]-x[b])*(y[b]-y[a]);
}
void check1()
{
    d=1,f=2;
    if(!gx(1,2,3))
    {
        for(int i=4; i<=n; i++)
            if(gx(2,3,i))
            {
                d=2,f=3;
                return;
            }
        for(int i=4; i<=n; i++)
            if(gx(1,3,i))
            {
                d=1,f=3;
                return;
            }
    }
}
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>x[i]>>y[i];
    if(n<5)
        cout<<"YES";
    else
    {
        check1();
        for(int i=1; i<=n; i++)
        {
            if(!gx(d,f,i))V.push_back(i);
        }
        if(V.size()<3)
            cout<<"YES";
        else
        {
            int f=1;
            for(int i=2;i<(int)V.size();i++)
                if(!gx(V[0],V[1],V[i]))f=0;
            if(f)cout<<"YES";
            else cout<<"NO";
        }
    }
    return 0;
}

 又改的代码,这样写还能判断平行,思路更清晰,我选择这个写法

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll x[N],y[N];
int n;
bool gx(int a,int b,int c,int d)
{
    return (x[b]-x[a])*(y[d]-y[c])==(x[d]-x[c])*(y[b]-y[a]);
}
int check(int d,int f)
{
    vector<int>V;
    for(int i=1; i<=n; i++)
        if(!gx(d,f,f,i))V.push_back(i);
    if(V.size()<3)return 1;
    for(int i=2; i<(int)V.size(); i++)
        if(!gx(V[0],V[1],V[1],V[i]))return 0;
    return 1;
}
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>x[i]>>y[i];
    if(n<5||check(1,2)||check(2,3)||check(1,3))
        cout<<"YES";
    else cout<<"NO";
    return 0;
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!