栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

Codeforces Round #481 (Div. 3) ABCDEFG

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Codeforces Round #481 (Div. 3) ABCDEFG

Problem - A - Codeforces

input

6
1 5 5 1 6 1

output

3
5 6 1 

input

5
2 4 2 4 4

output

2
2 4 

input

5
6 6 6 6 6

output

1
6 

倒序输出

#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int n; cin>>n;
    int a[200200];
    for(int i=1;i<=n;i++) cin>>a[i];
    map mp;
    vector vi;
    for(int i=n;i>=1;i--)
    {
        mp[a[i]]++;
        if(mp[a[i]]==1) vi.push_back(a[i]);
    }
    cout<=0;i--)
        cout< 

Problem - B - Codeforces

 input

6
xxxiii

output

1

input

5
xxoxx

output

0

input

10
xxxxxxxxxx

output

8
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    //int t; cin>>t;while(t--){
    int n; cin>>n;
    char s[200200];
    for(int i=1;i<=n;i++) cin>>s[i];
    if(strstr(s,"xxx")!=NULL) cout<<"0"< 

 似乎我的strstr没进去运行过???数据问题吧!

Problem - C - Codeforces

 input

3 6
10 15 12
1 9 12 23 26 37

output

1 1
1 9
2 2
2 13
3 1
3 12

input

2 3
5 10000000000
5 6 9999999999

output

1 5
2 1
2 9999999994

lower_bound直接找位置 

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
long long int a[200200]={0},b[200200],dp[200200]={0};
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    long long int n,m; cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        dp[i]=dp[i-1]+a[i];
    }
    for(int i=1;i<=m;i++)
        cin>>b[i];
    for(int i=1;i<=m;i++) //cout< 

 Problem - D - Codeforces

input

4
24 21 14 10

output

3

input

2
500 500

output

0

input

3
14 5 1

output

-1

input

5
1 3 6 9 12

output

1

 自己没折腾出来,好失败,看了大佬的写法,慢慢摸出来。

#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int n; cin>>n;
    int a[200200],b[200200];
    for(int i=0;i>a[i];//这个题目如果用sort排序一下会wa17,我很疑惑
    int sum=0x3f3f3f3f;
    for(int i=-1;i<=1;i++)
    {//根据首两位推测出差
        for(int j=-1;j<=1;j++)
        {//-1-1, -10, -11,  0-1, 00, 01, 1-1, 10, 11
            b[0]=a[0]+i; b[1]=a[1]+j;
            int distance=b[1]-b[0];
            bool flag=true;
            int t=abs(i)+abs(j);
            for(int r=2;r1) { flag=false; break; }
                else { if(b[r]!=a[r]) t++; }
            }
            if(flag==true) sum=min(sum,t);
        }
    }
    if(sum==0x3f3f3f3f) cout<<"-1"< 

Problem - E - Codeforces

input

3 5
2 1 -3

output

3

input

2 4
-1 1

output

4

input

4 10
2 4 1 2

output

2

 找极值

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int a[200200],sum=0;
int dp[200200]={0},minn=0,maxn=0;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int n,w; cin>>n>>w;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    for(int i=1;i<=n;i++)
    {
        dp[i]=dp[i-1]+a[i];
        minn=min(minn,dp[i]); maxn=max(maxn,dp[i]);
    } //cout<w||maxn>w||sum>w) cout<<"0"< 

Problem - F - Codeforces

 input

4 2
10 4 10 15
1 2
4 3

output

0 0 1 2 

input

10 4
5 4 1 5 4 3 7 1 2 5
4 6
2 1
10 8
3 5

output

5 4 0 5 3 3 9 0 2 5 

注意特判负数的输出即可。 

#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int n,k; cin>>n>>k;
    int a[200200],b[200200];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b+1,b+1+n);
    map mp;
    while(k--)
    {
        int x,y; cin>>x>>y;
        // 谁更大则说明谁要减少一个徒弟
        if(a[x]>a[y]) mp[x]++;
        else if(a[x]

Problem - G - Codeforces

 input

5 2
1 3 1
1 5 1

output

1 2 3 0 3 

input

3 2
1 3 1
1 2 1

output

-1

input

10 3
4 7 2
1 10 3
8 9 1

output

2 2 2 1 1 0 4 3 4 4 

 注意-1的类型的判断即可。给我整出来了,真不容易吖!

#include
#include
#include
#include
#include
#include
#include
using namespace std;
int a[200200],s[200200],d[200200],c[200200],sum=0;
int f[200200];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;//n天 m场考试
    int ans=0;
    bool flag=true;
    for(int i=1;i<=m;i++)
    {
        cin>>s[i]>>d[i]>>c[i]; //第一场的报送时间 哪天考 要准备多少天
        if(d[i]-s[i]d[j]) swap(d[i],d[j]),swap(s[i],s[j]),swap(c[i],c[j]),swap(a[i],a[j]);
        }
    }//按照考试先后时间顺序排列
    //for(int i=1;i<=m;i++) cout<=d[i]) flag=false;
        }
    }
    int flagg=0;
    for(int i=1;i<=n;i++)
        if(f[i]!=0&&f[i]!=m+1) flagg++;
    //for(int i=1;i<=n;i++) cout<
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/630495.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号