codeforces #150 div2 总结

只做了3题

A,读懂题意就行了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int n,k;
vector<int> a;
int b[35];
int main()
{
    int i,j,tmp;
    while(cin>>n>>k)
    {
        a.clear();
        for(i=1;i<=n*k;++i)
            a.push_back(i);
        for(i=1;i<=k;++i)
            cin>>b[i],a.erase(find(a.begin(),a.end(),b[i]));
        for(i=1,j=0;i<=k;++i)
        {
            cout<<b[i];
            tmp=n-1;
            while(tmp--)
            {
                cout<<" "<<a[j];
                j++;
            }
            cout<<endl;
        }
    }
    return 0;
}

 

B,暴力搜索,题意是说给一个数n(1<=n<=10^9),问小于等于n的数x有多少,其中x最多只能由2种数字构成。搜索一下10^9内的全部x,并由小到大存储到数组中,利用stl中的lower_bound求出给定的数n在数组中的一个上界,根据下界对应的index就能求出答案了,这里lower_bound返回的数大于等于n

 

#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
queue<int> q;
int l[200000];
int cnt=0;
bool judge(int c)
{
    set<int> t;
    t.clear();
    while(c)
        t.insert(c%10),c/=10;
    if(t.size()<=2)
        return 1;
    else
        return 0;
}
void bfs()
{
    while(!q.empty())
        q.pop();
    q.push(0);
    int i,t,c;
    while(!q.empty())
    {
        c=q.front();
        q.pop();
        for(i=0;i<10;++i)
        {
            t=c*10+i;
            if(t>0&&t<1000000000&&judge(t))
            {
                l[cnt++]=t;
                q.push(t);
            }
        }
    }
    l[cnt++]=1000000000;
//    int tmp=cnt;
//    while(tmp--)
//        cout<<l[tmp]<<endl;
}
int main()
{
    int n,ans,*t;
    bfs();
    while(cin>>n)
    {
        t=lower_bound(l,l+cnt,n);
        ans=t-l+1;
        if(*t!=n)
            ans--;
//        1 2 3 4 5 6 7 8 9 10 11 12 13 100 101 110
        cout<<ans<<endl;
    }
    return 0;
}
            

 

C,dp,题意是给n(1<=n<=10^5)个非负整数,定义一个运算f(l,r)为求这段区间内所有数的或运算的和,问f(l,r)能有多少种不同的结果。直接枚举的话10^10超时,这里用一个set<int> dp[i]记录所有的f(l,i)的结果,dp[i+1]=ai|dp[i],然后再把所有的结果加到一个set里,利用set的自动去重就得到最终结果了。

 

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
set<int> p,c,t;
int n,a[100005];
int main()
{
    long long ans;
    int i;
    set<int>::iterator it;
    while(cin>>n)
    {
        for(i=1;i<=n;++i)
            cin>>a[i];
        p.clear(),c.clear(),t.clear(),ans=0;
        for(i=1;i<=n;++i)
        {
            c.clear();
            c.insert(a[i]);
            for(it=p.begin();it!=p.end();++it)
                c.insert(a[i]|*it);
            t.insert(c.begin(),c.end());
//            printSet(c);
            p.swap(c);
//            printSet(p);
        }
        ans=t.size();
        cout<<ans<<endl;
    }
    return 0;
}  


 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值