AtCoder Beginner Contest 155 【A - E】

題目來源:https://atcoder.jp/contests/abc155/tasks
不得不吐槽,感覺D比E難多了
然後自己的表現就是A題人傻了 大小寫沒看清楚白嫖一發WA
D題自己有思路 但是不太相信atcoder的機子能跑 就沒敢寫
在這裏插入圖片描述


A - Poor

萌新題 不解釋 (萌新只要看主函數就夠啦<3)

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const int bb=18;
const double eps=1e-10;
const double pi=acos(-1);
int n,m;
char str[N];
int f[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    int a,b,c;
    rrr(a,b,c);
    if((a==b&&b!=c)||(a==c&&b!=c)||(b==c&&a!=b)){
            cout<<"Yes\n";
    }
    else cout<<"No\n";
    return 0;
}


B - Papers, Please

也不難吧 xd

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const int bb=18;
const double eps=1e-10;
const double pi=acos(-1);
int n,m;
char str[N];
int f[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    r(n);
    bool flag=1;
    FOR(i,1,n) r(f[i]);
    FOR(i,1,n){
        if(f[i]&1) ;
        else{
            if(f[i]%3!=0&&f[i]%5!=0){
                flag=0;
                break;
            }
        }
    }
    if(flag) cout<<"APPROVED\n";
    else cout<<"DENIED\n";
    return 0;
}


C - Poll

這題靈活運用STL ,其實是偷懶嘛

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const int bb=18;
const double eps=1e-10;
const double pi=acos(-1);
int n,m;
char str[N];
int f[N];
map<string,int> mm;
vector<string> v;
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    r(n);
    string ss;
    FOR(i,1,n){
        cin>>ss;
        mm[ss]++;
    }
    map<string,int>::iterator it;
    int maxx=0;
    for(it=mm.begin();it!=mm.end();it++){
        maxx=max(maxx,it->second);
    }
    for(it=mm.begin();it!=mm.end();it++){
        if(it->second==maxx) v.push_back(it->first);
    }
    sort(v.begin(),v.end());
    for(string s:v) cout<<s<<endl;
    return 0;
}


D - Pairs

毒瘤題 感覺在CCPC wannafly集訓營見過類似的 但那次是隊友寫的
具體的思路就是二分答案 然後對每個區間nlog(n)的查找比他大的有多少個,總複雜度O(nlogn)但有個奇大無比的常數60 ,所以我沒敢寫 但是最後過了

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const int bb=18;
const double eps=1e-10;
const double pi=acos(-1);
LL n,m;
char str[N];
LL f[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    r(n); r(m);
    LL cnt0=0,cnt1=0,cnt2=0;
    FOR(i,1,n){
        r(f[i]);
        if(f[i]>0) cnt1++;//+
        else if(f[i]<0) cnt2++;//-
        else cnt0++;//0
    }
    sort(f+1,f+n+1);
    if(cnt1*cnt2>=m){//-
        LL l=-1e18,r=-1;
        LL ans;
        while(l<=r){
            LL mid=(l+r)>>1;
            LL sum=0;

            FOR(j,1,cnt2){
                LL ll=cnt2+cnt0+1,rr=n;
                LL res=cnt2+cnt0;
                while(ll<=rr){//最大的乘積大於mid的pos
                    LL midd=(ll+rr)>>1;
                    if(f[j]*f[midd]>mid){
                        res=midd;
                        ll=midd+1;
                    }
                    else rr=midd-1;
                }
                //cout<<res<<endl;
                sum+=res-(cnt2+cnt0);
            }
            //cout<<mid<<' '<<sum<<endl;
            if(sum<=cnt1*cnt2-m){
                ans=mid;
                r=mid-1;
            }
            else l=mid+1;

        }
        cout<<ans<<endl;
        return 0;
    }
    m-=cnt1*cnt2;
    if(m<=cnt0*(cnt1+cnt2)+cnt0*(cnt0-1)/2){
        cout<<0<<endl;
        return 0;
    }
    m-=cnt0*(cnt1+cnt2)+cnt0*(cnt0-1)/2;
    LL l=1,r=1e18;
    LL ans;
    //cout<<m<<endl;
    while(l<=r){
        LL mid=(l+r)>>1;
        LL sum=0;
        FOR(j,1,cnt2){
            LL ll=j+1,rr=cnt2;
            LL res=j;
            while(ll<=rr){//最大的乘積大於mid的pos
                int midd=(ll+rr)>>1;
                if(f[j]*f[midd]>mid){
                    res=midd;
                    ll=midd+1;
                }
                else rr=midd-1;
            }
            sum+=res-j;
        }
        FOR(j,cnt0+cnt2+1,n){
            LL ll=j+1,rr=n;
            LL res=n+1;
            while(ll<=rr){
                LL midd=(ll+rr)>>1;
                if(f[j]*f[midd]>mid){
                    res=midd;
                    rr=midd-1;
                }
                else ll=midd+1;
            }
            sum+=n-ll+1;
        }
        if(sum<=cnt1*(cnt1-1)/2+cnt2*(cnt2-1)/2-m){
            ans=mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    cout<<ans<<endl;
    return 0;
}


E - Payment

這題就有一丟丟的高精度進位,對於每一位 要麼正着給 要麼反着要別人找 如果是1 - 4 肯定是給方便 ,6-9 肯定反正找方便 ,但如果是5 就判斷下一位是不是比5大 大的話就反着 否則正着

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const int bb=18;
const double eps=1e-10;
const double pi=acos(-1);
int n,m;
char str[N];
int f[N+100];
map<string,int> mm;
vector<string> v;
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    scanf("%s",str+1);
    LL ans=0;
    int len=strlen(str+1);
    FOR(i,1,len){
        f[i]=str[len-i+1]-'0';
    }
    FOR(i,1,len+15){
        if(f[i]>=10){
            f[i]-=10;
            f[i+1]++;
        }
        if(f[i]>=6){
            ans+=10-f[i];
            f[i+1]++;
        }
        else if(f[i]==5){
            ans+=5;
            if(f[i+1]>=5){
                f[i+1]++;
            }
        }
        else ans+=f[i];
    }
    cout<<ans<<endl;
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章