单排 Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/JiangHxin/article/details/102761763

to sum up:

Group 2/1/1 title, should be improved, short-term goal 3/3/3.
Disadvantages:

  1. Reading not.
  2. Topic doing too little, do not know how to open a dynamic map, stuck B title.
  3. Not considered a special case, C boundary question and did not deal with special circumstances.
  4. Knowledge weak points (game theory).

A - Forgetting Things

Thinking: read the questions, erasing every odd bit, so long as the output to the even 2 * x.


 #include<bits/stdc++.h>
#define ll long long
#define R register int
#define inf 0x3f3f3f3f
#define mod 1000000007;
using namespace std;
inline ll read(){
   ll s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put1(){ puts("YES") ;}
void put2(){ puts("NO") ;}
 
const int manx=5e4+5;;
 
int a[26];
int main()
{
    ll n,m;
    n=read(),m=read();
    if(n==9&&m==1) cout<<n<<" "<<m*10<<endl;
    else if(n==m) cout<<n*10<<" "<<m*10+1<<endl;
    else if(m-n==1) cout<<n*10+9<<" "<<m*10<<endl;
    else puts("-1");
 
    return 0;
}

B1 - TV Subscriptions (Easy Version)

Idea: to meet the minimum number of cells painted black cross, not because of the dynamic open the map, I have not seen this problem, ignorant, just open the map difference this off, you can simulate.

#include<bits/stdc++.h>
#define ll long long
#define R register int
#define inf 0x3f3f3f3f
#define mod 1000000007;
using namespace std;
inline ll read(){
   ll s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put1(){ puts("Yes") ;}
void put2(){ puts("No") ;}
 
const int manx=2e5+5;;
 
ll a[manx];
map<ll,ll>b;
 
int main()
{
    ll q;
    q=read();
    while(q--)
    {
        ll n,k,d;
        n=read(),k=read(),d=read();
        b.clear();
        ll ans=0,res=0;
        for(int i=1;i<=n;i++)
            a[i]=read();
        set<ll>q;
        for(int i=1;i<=d;i++)
            q.insert(a[i]),b[a[i]]++;
        ans=q.size();
        for(int i=d+1;i<=n;i++)
        {
            q.insert(a[i]);
            b[a[i]]++;
            b[a[i-d]]--;
            if(!b[a[i-d]]) q.erase(a[i-d]);
            ans=min(ans,(ll)q.size());
        }
        cout<<ans<<endl;
    }
    return 0;
}

B2 - TV Subscriptions (Hard Version)

Thinking: t array tag number string of letters, and then double pointer traversal s p, s and finally judged whether the length of the string and a corresponding pointer equal (less the PM judgment).

#include<bits/stdc++.h>
#define ll long long
#define R register int
#define inf 0x3f3f3f3f
#define mod 1000000007;
using namespace std;
inline ll read(){
   ll s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put1(){ puts("Yes") ;}
void put2(){ puts("No") ;}
 
const int manx=2e5+5;;
 
ll a[manx];
map<ll,ll>b;
 
int main()
{
    ll q;
    q=read();
    while(q--)
    {
        ll n,k,d;
        n=read(),k=read(),d=read();
        b.clear();
        ll ans=0,res=0;
        for(int i=1;i<=n;i++)
            a[i]=read();
        set<ll>q;
        for(int i=1;i<=d;i++)
            q.insert(a[i]),b[a[i]]++;
        ans=q.size();
        for(int i=d+1;i<=n;i++)
        {
            q.insert(a[i]);
            b[a[i]]++;
            b[a[i-d]]--;
            if(!b[a[i-d]]) q.erase(a[i-d]);
            ans=min(ans,(ll)q.size());
        }
        cout<<ans<<endl;
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/JiangHxin/article/details/102761763