Div. 2, based on technology 2020 elimination round 2

Keywords: less

Conclusion:

Group 2 / 1 / 1 questions, to be improved, near-term goal 3 / 3 / 3.
Disadvantages:

  1. English reading is not good.
  2. I didn't know how to open a map dynamically, so I was stuck by problem B.
  3. Without considering the special situation, the boundary and special situation of question C were not handled well.
  4. Weak knowledge points (game theory).

A - Forgetting Things

Idea: to read the topic, every time you delete the odd number, so just output the even number 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: meet the minimum number of squares with black crosses. Because the map cannot be opened dynamically, this problem has not been solved. It's just a matter of simulation.

#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)

Idea: array marks the number of letters in string t, then double pointer traverses s and p, and finally determines whether the length of string s is equal to the corresponding pointer (less this judgment in the afternoon).

#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;
}

Posted by Daveyz1983 on Sat, 26 Oct 2019 07:30:09 -0700