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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值