2015 Multi-University Training Contest 6

hdu 5363

/******************hdu 5363 **********************
/*求一个集合元素里偶数和的子集个数
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int N = 1000005 + 10;
const int MOD=1000000007;
LL t,n,m;
LL poww(LL a,LL b,LL MOD)
{
    LL res=1;
    while(b)
    {
        if(b&1) res=(res*a)%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int main()
{
    while(~scanf("%I64d",&t))
    {
        for(int i=0; i<t; ++i)
        {
            scanf("%I64d",&n);
            m=poww(2,n-1,MOD);
            m+=MOD;
            printf("%I64d\n",(m-1)%MOD);
        }
    } return 0;
}

hdu 5360

【解题思路】:

结构体 + 优先队列,首先第一个人的L[i]必须是0,然后在同样的下标为L[i]的进队列,然后队列中的元素按照r[i]的大小排序,使得R[i]最小的优先

/*题意:现在有n个人,然后soda想要n个人尽可能多的去野营,每个人去野营是要在soda询问他时,

每个人所知道的去的人数大于等于L[i] 小于等于R[i]  然后问哪种询问顺序,可以使去的人数最多
*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>

using namespace std;
const int N=1000005;

struct item{
    int ll,rr,id;
    bool operator < (const item &aa) const{
        return rr>aa.rr;
    }
    item(){
        ll=0;
        rr=0;
        id=0;
    }
}s[N];

bool cmp(item a,item b){
    if(a.ll!=b.ll) return a.ll<b.ll;
    return a.rr<b.rr;
}

int num[N];
int main(){
    //freopen("1.txt","r",stdin);
    int T,n;scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        for(int i=0; i<n; ++i) scanf("%d",&s[i].ll);
        for(int i=0; i<n; ++i) scanf("%d",&s[i].rr),s[i].id=i+1;
        sort(s,s+n,cmp);

    /*    cout<<"bug begin!!!!!!!!!!!!!!!"<<endl;
        for(int i=0; i<n; ++i)
            cout<<"s[i].id="<<s[i].id<<" "<<"s[i].ll="<<s[i].ll<<" "<<"s[i].rr="<<s[i].rr<<endl;
        cout<<"bug end!!!!!!!!!!!!!!!"<<endl;
    */
        priority_queue <item>val;
        while(!val.empty()) val.pop();
        if(s[0].ll!=0){ ///第一个元素不符合
            puts("0");
            for(int i=0; i<n; ++i)
                printf("%d%c",i+1,i==n-1?'\n':' ');
            continue;
        }
        int i=1,cur=0,c1=0,c2=n-1;///cur:邀请人个数,c1:接受人数
        val.push(s[0]);
        while(!val.empty()){
   //      cout<<"bug begin!!!!!!!!!!!!!!!"<<endl;
   //      cout<<"cur="<<cur<<" pre c1="<<c1<<" "<<"val.top().id="<<val.top().id<<" "<<"val.top().ll="<<val.top().ll<<"val.top().rr="<<val.top().rr<<endl
   //         cout<<"bug end!!!!!!!!!!!!!!!"<<endl;
            for(;s[i].ll==cur&&i<n;++i) val.push(s[i]);
            while(!val.empty()){
                if(val.top().rr>=cur){
                    int t=val.top().id;
                    num[c1++]=t;
                    cur++;
                    val.pop();
                    break;
                }
                else num[c2--]=val.top().id;
                val.pop();
            }
          for(;s[i].ll==cur&&i<n; ++i) val.push(s[i]);
 //       cout<<"last c1="<<c1<<endl;
        }
  //      cout<<"zhong ce c1="<<c1<<endl;
        for(; i<n; ++i) num[c2--]=s[i].id;
        printf("%d\n",c1);
        for(int i=0; i<n; ++i) printf("%d%c",num[i],i==n-1?'\n':' ');
    } return 0;
}


hdu 5355,


/****************hdu 5355 ******************
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int N =2e5 + 10;
const int MOD=1000000007;
bool vis[N];
int ans[N];
int t,n,m;
int main()
{
    scanf("%d",&t);
    while(t--){
        scanf("%d %d",&n,&m);
        memset(ans,0,sizeof(ans));
        int sum=((n+1)*n)/2;
        int mm=sum/m;
        if(sum%m==0&&mm>m){
            puts("YES");
            memset(vis,false,sizeof(vis));
            while(m--){
                int su=0;
                int cnt=0;
                for(int i=n;i>=1;i--){
                     if(!vis[i]&&su+i<=mm){
                         vis[i]=true;
                         ans[cnt++]=i;
                         su+=i;
                         if(su==mm){
                            break;
                         }
                     }
                }
                sort(ans,ans+cnt);
                printf("%d %d",cnt,ans[0]);
                for(int i=1; i<cnt; ++i) printf(" %d",ans[i]);
                puts("");
            }
        }
        else puts("NO");
    } return 0;
}


你可能感兴趣的:(多校联合)