codeforces 305 我太水了,加把劲锕。

A:不难,题意能难搞懂。

题意:给定n个数,从中选出k个,使他们的个位,十位,百位,上的数字只有一个不是0。

思路:数据小,先判0和100,再判各位和十位。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <string>
#define LL long long
#define DB double
using namespace std;
int re[109];
int v[109];
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&re[i]);
    sort(re,re+n);
    int ans = (re[0]==0);
    int rr[109],cnt = 0;
    if(re[0]==0) rr[cnt++] = 0;
    if(re[n-1]==100) ans++,rr[cnt++] = 100;
    if(re[0]==0) re[0] = re[1];
    if(re[0]) ans++,rr[cnt++] = re[0];
    if(re[0]<10)
    {
        for(int j=0;j<n;j++)
        if(re[j]%10==0&&re[j]!=100)
        {
            ans++;
            rr[cnt++] = re[j];
            break;
        }
    }
    ans = min(ans,n);
    printf("%d\n",ans);
    for(int i=0;i<ans;i++)
    {
        if(i) printf(" ");
        printf("%d",rr[i]);
    }printf("\n");
    return 0;
}

B题,犯了一个很sb的错,当我lock的瞬间发现数据类型定义错了。今天发现两个数相乘会超longlong。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <string>
#define LL long long
#define DB double
using namespace std;
unsigned LL p,q;
int n;
unsigned LL re[109];
int solve()
{
    for(int i=0;i<n;i++)
    {
        if(re[i]&&q&&p/q<re[i]) return 0;
        p-=re[i]*q;
        if(p<0) return 0;
        if(i==n-1)
        {
            if(p!=0) return 0;
        }
        swap(p,q);
    }
    return 1;
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    cin>>p>>q;//cout<<p<<" "<<q<<endl;
    scanf("%d",&n);
    for(int i=0;i<n;i++) cin>>re[i];
    if(solve()) printf("YES\n");
    else printf("NO\n");
    return 0;
}

C题:随便yy了一下。居然过了。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <string>
#define LL long long
#define DB double
using namespace std;
LL a;
int n;
const int N = 100009;
LL re[N];
LL v[N];
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    scanf("%d",&n);
    int cnt = -1 ;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(cnt==-1)
        {
            re[++cnt] = a;
            v[cnt] = 1;
        }else
        {
            if(re[cnt]==a)
            {
                v[cnt]++;
            }else
            {
                re[++cnt] = a;
                v[cnt] = 1;
            }
        }
    }
    LL k = 0;
    for(int i=0;i<cnt;i++)
    {
        LL tmp = v[i];
        for(int j=0;j<(re[i+1]-re[i])&&tmp;j++)
        {
            if(tmp%2)
            {
                k++;
            }tmp/=2;
        }
        v[i+1] += tmp;
    }
    //cout<<re[cnt]<<" "<<k<<endl;
    LL ans= re[cnt] - k;
    LL tmp = v[cnt];
    while(tmp)
    {
        if(tmp%2==0) ans++;
        tmp/=2;
    }
    cout<<ans<<endl;
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值