Codeforces Round #590 (Div. 3)(e、f待补

https://codeforces.com/contest/1234/problem/A

A. Equalize Prices Again

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int main(){
 5     int n,a;
 6     int t;
 7     cin>>t;
 8     ll sum = 0,ans;
 9     while(t--){
10         cin>>n;sum = 0;
11         for(int i = 0;i < n;++i){
12             cin>>a;sum+=a;
13         }
14         ans = sum/n;
15         if(sum%n)ans+=1;
16         cout<<ans<<endl;
17     }
18 }

AC代码

https://codeforces.com/contest/1234/problem/B1

B1. Social Network (easy version)

https://codeforces.com/contest/1234/problem/B2

B2. Social Network (hard version)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a;
int n ,k ,now=0,fi=0;
vector<ll>s;
map<ll,int>mp;
int main(){
    cin>>n>>k;
    for(int i = 0;i < n;++i){
        cin>>a;
        if(mp[a]==0){
                mp[a]=1;s.push_back(a);
            if(now<k){
                now++;
            }
            else if(now==k){
                mp[s[fi]]=0;fi++;
            }
        }
    }
    cout<<now<<endl;
    int l =s.size()-1;
    int cnt=0;
    while(cnt<now&&l>=0){
        if(mp[s[l]])cnt++,cout<<s[l]<<" ";
        l--;
    }
    cout<<endl;

    return 0;
}

AC代码

https://codeforces.com/contest/1234/problem/C

C. Pipes

旋转一遍发现前两种其实是不同方向摆放的一种管道,后四个同理,也就是只有两个管道,一个是直流另一个会变向,然后问题就很简单了。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4
 5 int main(){
 6     int t,n;
 7     cin>>t;
 8     while(t--){
 9         cin>>n;
10         string a[3];cin>>a[0]>>a[1];
11         int now=0,flag =1;
12         for(int i = 0;i <n;++i){
13             if(a[now][i]==‘1‘||a[now][i]==‘2‘)continue;
14             else{
15                now=1-now;
16                if(a[now][i]==‘1‘||a[now][i]==‘2‘){
17                 flag=0;break;
18                }
19             }
20         }
21         if(flag==0||now==0)cout<<"no"<<endl;
22         else cout<<"yes"<<endl;
23     }
24     return 0;
25 }

AC代码

https://codeforces.com/contest/1234/problem/D

D. Distinct Characters Queries

用线段树维护不同字母的个数orz学到了新东西,待会再看看set的做法?

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+7;
int a[N],ans[30];
int tree[4*N][26];
void build(int l,int r,int rt){
    if(l==r){tree[rt][a[l]]++;return ;}
    int mid=(l+r)/2;
    build(l,mid,rt*2);
    build(mid+1,r,rt*2+1);
    for(int i = 0;i < 26;++i)tree[rt][i]=tree[rt*2][i]+tree[rt*2+1][i];
}
void f5(int l,int r,int rt,int x,int p,int f){
    if(l==r){tree[rt][p]--;tree[rt][f]++;return ;}
    int mid=(l+r)>>1;
    if(x<=mid)f5(l,mid,rt<<1,x,p,f);
    else f5(mid+1,r,rt<<1|1,x,p,f);
    for(int i = 0;i < 26;++i)tree[rt][i]=tree[rt<<1][i]+tree[rt<<1|1][i];
}
void query(int l,int r,int rt,int ll,int rr){
    if(r<=rr&&l>=ll){
        for(int i = 0;i < 26;++i)ans[i]+=tree[rt][i]; return ;
    }
    int mid=(l+r)>>1;
    if(ll<=mid)query(l,mid,rt<<1,ll,rr);
    if(rr>mid)query(mid+1,r,rt<<1|1,ll,rr);
}
int main()
{
    ios::sync_with_stdio(0);
    string s;cin>>s;int n = s.size();
    for(int i = 0;i < n;++i)a[i+1]=s[i]-‘a‘;
    build(1,n,1);
    int m;cin>>m;
    while(m--){
        int flag,x,l,r;char c;cin>>flag;
        if(flag==1){
            cin>>x>>c;
            f5(1,n,1,x,s[x-1]-‘a‘,c-‘a‘);
            s[x-1]=c;
        }
        else{
            cin>>l>>r;memset(ans,0,sizeof(ans));
            query(1,n,1,l,r);
            int tot=0;
            for(int i = 0;i < 26;++i)if(ans[i])tot++;
            cout<<tot<<endl;
        }
    }
    return 0;
}

AC代码

原文地址:https://www.cnblogs.com/h404nofound/p/11619524.html

时间: 2024-08-01 01:42:42

Codeforces Round #590 (Div. 3)(e、f待补的相关文章

Codeforces Round #590 (Div. 3) Editorial

Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同的价格,找出一个最小的可能值price,使得price * n >= sum,sum指的是原来商品价格的总和. 知识点:模拟 思路:求出sum/n向上取整即可,有两种方法.一是使用ceil()函数,但注意ceil()返回的是向上取整后的浮点数,所以要进行强制类型转换:二是直接向下取整,然后用if语句

Codeforces Round #590 (Div. 3) F

传送门 题意: 给出一个只含前\(20\)个字符的字符串,现在可以选择一段区间进行翻转,问区间中字符各不相同时,最长长度为多少. 思路: 首先,容易将题意转换为选择两个字符各不相同的区间,然后长度相加取最大: 注意到字符串中满足条件的区间长度不超过\(20*n\),那么处理出所有区间,现在任务即为找到两个区间,其字符各不想同,且长度和最大: 因为最多\(20\)个字符,将满足条件的区间转换为二进制数,任务转换为找到两个数\(a_i,a_j\)满足\(a_i\&a_j=0\)且二进制为\(1\)的

Codeforces Round #541 (Div. 2) (A~F)

目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路) F.Asya And Kittens(链表) G.Most Dangerous Shark Codeforces 1131 比赛链接 hack一个暴力失败了两次最后还是没成功身败名裂= = CF跑的也太快了吧... 不过倒也涨了不少. A.Sea Battle //想麻烦了,但是无所谓... #

Codeforces Round #590 (Div. 3)

D. Distinct Characters Queries Description You are given a string ss consisting of lowercase Latin letters and qq queries for this string. Recall that the substring s[l;r]s[l;r] of the string ss is the string slsl+1…srslsl+1…sr. For example, the subs

Codeforces Round #590 (Div. 3) D. Distinct Characters Queries(线段树, 位运算)

链接: https://codeforces.com/contest/1234/problem/D 题意: You are given a string s consisting of lowercase Latin letters and q queries for this string. Recall that the substring s[l;r] of the string s is the string slsl+1-sr. For example, the substrings

Codeforces Round #496 (Div. 3)A~F

(寒假训练赛,也是lj难得补完的一场 https://codeforces.com/contest/1005 A.题意是  每一个楼梯有x个台阶,小女孩爬楼的时候会从1开始数每层楼有几个台阶,现在给给出n个数字a1~an,代表着小女孩爬楼时数数的序列,求有多少层楼梯,并且输出每层楼梯台阶数. 解法:for循环模拟小女孩从1开始数,数到下一个1的话楼层++,然后把他前一个数存进去. int now = 0; for(int i = 0;i < n;++i){ cin>>a; if(a ==

Codeforces Round #516 (Div. 2) (A~F)

目录 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Labyrinth(BFS) E.Dwarves,Hats and Extrasensory Abilities(交互 二分) D.Labyrinth E.Dwarves,Hats and Extrasensory Abilities 比赛链接 A.Make a triangle! 不放了. B.Equations of Mathema

Codeforces Round #590 (Div. 3) B2. Social Network (hard version)

链接: https://codeforces.com/contest/1234/problem/B2 题意: The only difference between easy and hard versions are constraints on n and k. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most

Codeforces Round #590 (Div. 3) C. Pipes

链接: https://codeforces.com/contest/1234/problem/C 题意: You are given a system of pipes. It consists of two rows, each row consists of n pipes. The top left pipe has the coordinates (1,1) and the bottom right - (2,n). There are six types of pipes: two