Codeforces Round #368 (Div. 2) ABCD

A. Brain‘s Photos

题解:

水得不要不要的

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define LL long long
#define CLR(x) memset(x,0,sizeof x)
#define MC(x,y) memcpy(x,y,sizeof(x))
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=200;
const int mod=1e9+7;
const int INF=1e9;

string p;
set<string> s;

int main(){
    s.insert("C");
    s.insert("M");
    s.insert("Y");
    int n,m,flag=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++){
        cin>>p;
        if(flag) continue;
        if(s.count(p)) flag=1;
    }
    if(!flag) cout<<"#Black&White"<<endl;
    else      cout<<"#Color"<<endl;
    return 0;
}

B.Chris and Magic Square

题解:

英语阅读题,看懂题意就很水了

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define LL long long
#define CLR(x) memset(x,0,sizeof x)
#define MC(x,y) memcpy(x,y,sizeof(x))
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=1e5+10;
const int mod=1e9+7;
const int INF=1e9+10;

int v[maxn],u[maxn],w[maxn];
set<int> s;

int main(){
    int n,m,k,tmp;
    cin>>n>>m>>k;
    for(int i=1;i<=m;i++) cin>>v[i]>>u[i]>>w[i];
    for(int i=1;i<=k;i++){
        cin>>tmp;
        s.insert(tmp);
    }
    int ans=INF;
    for(int i=1;i<=m;i++){
        if((s.count(v[i])&&!s.count(u[i]))||(!s.count(v[i])&&s.count(u[i])))
        ans=min(w[i],ans);
    }
    if(ans==INF) cout<<-1<<endl;
    else       cout<<ans<<endl;
}

C. Pythagorean Triples

题解:

百度一下勾股数就行了。。。

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define LL long long
#define CLR(x) memset(x,0,sizeof x)
#define MC(x,y) memcpy(x,y,sizeof(x))
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=200;
const int mod=1e9+7;
const int INF=1e9;

LL n,m,a,b,c;

int main(){
    cin>>n;
    if(n<3) cout<<-1<<endl;
    else{
        if(n&1){
            b=(n*n-1*1LL)/2*1LL;
            c=(n*n+1*1LL)/2*1LL;
        }
        else{
            b=(n*n/2-2*1LL)/2*1LL;
            c=(n*n/2+2*1LL)/2*1LL;
        }
        cout<<b<<" "<<c<<endl;
    }
    return 0;
}

D. Persistent Bookcase

题解:

考验码力的题目。。用上bitset,然后模拟就行了。

注意到一点,4种操作,更改的都是一行的值

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define LL long long
#define CLR(x) memset(x,0,sizeof x)
#define MC(x,y) memcpy(x,y,sizeof(x))
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<int,int> P;
const double eps=1e-9;
const int N=1e5+10;
const int M=1e3+10;
const int mod=1e9+7;
const int INF=1e9+10;

bitset<M> bs[N],tmp;
int que[N][M],ans[N],cnt;

int main(){
    int n,m,q,a,b,c;
    cnt=0;
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=m;i++) tmp[i]=1;
    for(int i=1;i<=q;i++){
        scanf("%d%d",&a,&b);
        if(a==4){
            for(int j=1;j<=n;j++) que[i][j]=que[b][j];
            ans[i]=ans[b];
            continue;
        }
        for(int j=1;j<=n;j++) que[i][j]=que[i-1][j];
        ans[i]=ans[i-1];
        int id=que[i-1][b];
        if(a==3){
            bs[++cnt]=bs[id];
            ans[i]-=bs[cnt].count();
            bs[cnt]^=tmp;
            ans[i]+=bs[cnt].count();
            que[i][b]=cnt;
        }
        if(a==2){
            scanf("%d",&c);
            if(bs[id][c]==0) continue;
            bs[++cnt]=bs[id];
            bs[cnt][c]=0;
            ans[i]--;
            que[i][b]=cnt;
        }
        if(a==1){
            scanf("%d",&c);
            if(bs[id][c]==1) continue;
            bs[++cnt]=bs[id];
            bs[cnt][c]=1;
            ans[i]++;
            que[i][b]=cnt;
        }
    }
    for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
    return 0;
}
时间: 2025-01-04 20:41:03

Codeforces Round #368 (Div. 2) ABCD的相关文章

Codeforces Round #368 (Div. 2) Brain&#39;s Photos

Brain's Photos Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos

Codeforces Round #258 (Div. 2)[ABCD]

Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意: Akshat and Malvika两人玩一个游戏,横竖n,m根木棒排成#型,每次取走一个交点,交点相关的横竖两条木棒要去掉,Akshat先手,给出n,m问谁赢. 分析: 水题,很明显不管拿掉哪个点剩下的都是(n-1,m-1),最后状态是(0,x)或(x,0),也就是拿了min(n,m)-1次,

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T

Codeforces Round #Pi (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/567 听说Round #Pi的意思是Round #314... A. Lineland Mail time limit per test:3 seconds memory limit per test:256 megabytes All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with it

Codeforces Round #250 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory limit per test:256 megabytes Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between th

Codeforces Round #143 (Div. 2) (ABCD 思维场)

题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test:256 megabytes One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually

Codeforces Round #249 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/435 A. Queue on Bus Stop time limit per test:1 second memory limit per test:256 megabytes It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of p

Codeforces Round #313 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/560 水笔场... A. Currency System in Geraldion time limit per test:2 seconds memory limit per test:256 megabytes A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several va