Codeforces Round #606 Div. 2 比赛情况

比赛情况

bq. A题 Wrong Answer on test 2 , E题sb题没切。bqbqbq.

比赛总结

bq.

那就直接上题解吧!^-^

A

数位dp,分类讨论。

Talk is cheap.Show me the code.

B

我们把数值一样的数放在一起,扔进堆里。按数值从大到小处理就OK了。

注意值域比较大,用一下 \(STL\) 里面的 map

Talk is cheap.Show me the code.

#include<bits/stdc++.h>
using namespace std;
inline int read() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
    return x * f;
}
const int N = 2e5+7;
int n;
int a[N];
void work() {
    map<int,int> s;
    priority_queue<int> q;
    n = read(); int ans = 0;
    for(int i=1;i<=n;++i) {
        a[i] = read();
        if(s[a[i]]==0) {
            q.push(a[i]);
        }
        ++s[a[i]];
    }
    while(!q.empty()) {
        int now = q.top(); q.pop();
        if(now&1) continue;
        if(s[now/2]==0) q.push(now/2);
        s[now/2] += s[now]; ans++;
        //printf("ans += s[%d], s[now]=%d\n",now,s[now]);
    }
    printf("%d\n",ans);
}
int main()
{
    //freopen("a.out","w",stdout);
    int T = read();
    while(T--) work();
    return 0;
}

C

贪心题。

如果有 twone 则删去 ‘o‘,否则删去中间这个,比如 one 删去 ‘n‘。这样是对的。

然后模拟即可。

Talk is cheap.Show me the code.

#include<bits/stdc++.h>
using namespace std;
inline int read() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
    return x * f;
}
void work() {
    string s; cin>>s; vector<int> Ans;
    for(int i=1;i<s.length();++i) {
        char a = s[i-1], b = s[i], c = s[i+1];
        if(a=='t' && b=='w' && c=='o') {
            if(s[i+2]=='n' && s[i+3]=='e') s[i+1] = '-', Ans.push_back(i+1)/*, i = i+3+1*/;
            else s[i] = '-', Ans.push_back(i)/*, i = i+1+1*/;
        } else if(a=='o' && b=='n' && c=='e') {
            Ans.push_back(i);
        }
    }
    printf("%d\n",(int)Ans.size());
    for(int i=0;i<Ans.size();++i) printf("%d ",Ans[i]+1);
    puts("");
}
int main()
{
    //freopen("a.out","w",stdout);
    int T = read();
    while(T--) work();
    return 0;
}

D

待补坑。

E

炒鸡简单

考虑一张下面这样的图:

答案不就是两个蓝色部分的大小相乘吗?(题目不考虑A,B两点)

这不就是Dfs的事吗qwq

(其实如果这两块蓝色的有边将他们连起来了就是 puts("0"))

Talk is cheap.Show me the code.

#include<bits/stdc++.h>
using namespace std;
inline int read() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
    return x * f;
}
const int N = 2e5+7, M = 5e5+7;
int n,m,a,b,cnt,flag,tot;
int head[N],vis[N];
struct Edge {
    int next,to;
}edge[M<<1];
inline void add(int u,int v) {
    edge[++cnt] = (Edge)<%head[u],v%>;
    head[u] = cnt;
}
void Dfs(int u,int F) {
    flag |= (u==F); vis[u] = 1; ++tot;
    for(int i=head[u];i;i=edge[i].next) {
        int v = edge[i].to;
        if(!vis[v]) Dfs(v,F);
    }
}
void work() {
    memset(head, 0, sizeof(head)); cnt = flag = 0;
    n = read(), m = read(), a = read(), b = read();
    for(int i=1,u,v;i<=m;++i) {
        u = read(), v = read();
        add(u,v), add(v,u);
    }
    memset(vis, 0, sizeof(vis));
    vis[a] = 1; int n1 = 0, n2 = 0, nxt = 0;
    for(int i=head[a];i;i=edge[i].next) {
        int v = edge[i].to; tot = 0; Dfs(v,b);
        if(flag) {
            n1 = n - tot - 1; break;
        }
    }
    memset(vis, 0, sizeof(vis));
    vis[b] = 1; flag = 0;
    for(int i=head[b];i;i=edge[i].next) {
        int v = edge[i].to; tot = 0; Dfs(v,a);
        if(flag) {
            n2 = n - tot - 1; break;
        }
    }
    printf("%lld\n",(long long)(1ll*n1*n2));
}
int main()
{
    int T = read();
    while(T--) work();
    return 0;
}

原文地址:https://www.cnblogs.com/BaseAI/p/12041116.html

时间: 2024-08-02 09:26:56

Codeforces Round #606 Div. 2 比赛情况的相关文章

Codeforces Round #606 (Div. 2) D. Let&#39;s Play the Words?(贪心+map)

?? ?? ?? 题意:给你一些序列,要求把这些序列翻转之后能首尾相连(01,10),并且字符串不能相同,询问最小步数: 1.我们只关心这个字符串首尾位置,一共只有四种情况:00,01,10,11:00 和 11 是没必要翻转的,剩下 01,10 只要存在就可以相互抵消(0110,1001这种),剩下多的 01 or 10,就是我们最后需要翻转的字符串,数量为abs(num01-num10)/2: 2.为了满足字符串不能相同,一开始就记录下哪写字符串不可以翻转,例,假如s翻转之后为rev,rev

Codeforces Round #614 (Div. 2) 比赛总结

比赛情况 怒切 \(A,B,C,D\),后面 \(E,F\) 两题技术太菜不会做,不知道什么时候可以补起来. 比赛总结 事实证明: 比赛前喝一瓶抗疲劳饮料对比赛状态的进入有显著效果. 比赛有人陪着打对AC题目有显著效果. 说正经的: 不要紧张,也不要太过放松.这样才有利于发挥出真实水平. 下面就开始 喜闻乐见 的题解吧. A 入门题 枚举找到最近的可用楼层即可.用 \(STL\) 里面的 map 判断一个楼层是否可用使用. Code #include<bits/stdc++.h> #defin

【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B:数学+排序 C:字符串搜索 A // https://codeforces.com/contest/1277/problem/A /* 题意: 给出一个数,求不大于该数的完美整数的个数(完美整数指全是一个数组成的数字,如:111, 333333, 444444, 9, 8888 ...) 分析:

Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

A. 签到题:思路为:所求答案 = 9 * (字符长度 - 1) + 最高位数 +(- 1)//通过判断语言确定是否需要再减个一 如果a****** > *******则需要加一反之不需要 #include <bits/stdc++.h> using namespace std; typedef long long ll; int main () { ll t; cin >> t; while(t--) { ll ans; ll temp = 0; string num; c

Codeforces Round #606 (Div. 2) E - Two Fairs(DFS,反向思维)

?? ?? ?? 题意:求点对中,满足要互达必须经过a,b两点的对数,图为无向连通图 若(x,y)要满足互达必须经过(a,b),反过来想, a必须通过b点到达y点:满足a--->b--->y: b必须通过a点到达x点:满足b--->a--->x,无向图:x--->a--->b: 连起来即为:x--->a--->b--->y: int vis[MAXN]; vector<int>edge[MAXN]; void dfs(int x,int e

【cf比赛记录】Codeforces Round #600 (Div. 2)

Codeforces Round #600 (Div. 2) ---- 比赛传送门 昨晚成绩还好,AC A,B题,还能上分(到底有多菜) 补了C.D题,因为昨晚对C.D题已经有想法了,所以补起题来也快.(C题TLE了,D题想用并查集没好) A // http://codeforces.com/contest/1253/problem/A /* 如果YES,则b[i] - a[i] 在一个区间里的差肯定是相同的且不小于0 */ #include<iostream> #include<cst

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces Round 239 Div 1

都怪自己太懒了 这段时间比赛参加了大部分,但是一直都没写题解,趁这几天没事,计划把这段时间的题解都补上. 上一次比赛(248)终于升到了div1,所以从这次开始就开始写div1了. A. Triangle There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such

*Codeforces Round #251 (Div. 2)AK)

A.确定性数学计算,水,读题要快 1 #include<iostream> 2 #include<stdio.h> 3 4 using namespace std; 5 int N,d; 6 int main(){ 7 while(~scanf("%d%d",&N,&d)){ 8 int cnt=0; 9 for(int i=0;i<N;i++){ 10 int t; 11 scanf("%d",&t); 12