zoukankan      html  css  js  c++  java
  • 多校训练赛2 ZCC loves cards

    ZCC loves cards

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 260    Accepted Submission(s): 7


    Problem Description
    ZCC loves playing cards. He has n magical cards and each has a number on it. He wants to choose k cards and place them around in any order to form a circle. He can choose any several consecutive cards the number of which is m(1<=m<=k) to play a magic. The magic is simple that ZCC can get a number x=a1⊕a2...⊕am, which ai means the number on the ith card he chooses. He can play the magic infinite times, but once he begin to play the magic, he can’t change anything in the card circle including the order. ZCC has a lucky number L. ZCC want to obtain the number L~R by using one card circle. And if he can get other numbers which aren’t in the range [L,R], it doesn’t matter. Help him to find the maximal R.
     

    Input
    The input contains several test cases.The first line in each case contains three integers n, k and L(k≤n≤20,1≤k≤6,1≤L≤100). The next line contains n numbers means the numbers on the n cards. The ith number a[i] satisfies 1≤a[i]≤100. You can assume that all the test case generated randomly.
     

    Output
    For each test case, output the maximal number R. And if L can’t be obtained, output 0.
     

    Sample Input
    4 3 1 2 3 4 5
     

    Sample Output
    7
    Hint
    ⊕ means xor
     

    题意:有N张牌。每张牌都有其权值ai。然后有一个幸运数L。从N个数取K个数围城一个圈,顺序随意。然后能够这个魔术师能够从这k张牌中取连续的随意张牌得到一个数值h=a1^a2^a3...假设他想要[L,R]这个范围的值都能取到,问R最大是多少。

    题解:用二进制状态把取出k的多种情况存入sta数组中。然后去模拟找出最大的R。TLE.

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    #include <cmath>
    #include <queue>
    #include <map>
    #include <stack>
    #include <list>
    #include <vector>
    using namespace std;
    #define LL __int64
    LL sta[100010];
    int a[50];
    int main()
    {
    	int n,m,i,j,k,i1,i2,i3,i4,i5,i6,L;
    	while (3==scanf("%d%d%d",&n,&m,&L))
    	{
    		memset(sta,0,sizeof(sta));
    		memset(a,0,sizeof(a));
    		LL t=0,s;
    		for (i=0;i<n;i++)
    			scanf("%d",&a[i]);
    		if (m==1) 
    		{
    			for (i=0;i<n;i++)
    				sta[++t]=1<<i;
    		}
    		else if (m==2)
    		{
    			for (i=0;i<n-1;i++)
    				for (i1=0;i1<n-(i+1);i1++)
    				{
    					s=(1<<(i+i1+1))+(1<<i1);
    					sta[++t]=s;
    				}
    		}
    		else if (m==3)
    		{
    			for (i=0;i<n-2;i++)
    				for (j=0;j<n-(i+1)-1;j++)
    					for (k=0;k<n-2-i-j;k++)
    					{
    					    s=(1<<(i+k+j+2))+(1<<(j+k+1))+(1<<k);
    						sta[++t]=s;
    					}
    		}
    		else if (m==4)
    		{
    			for (i=0;i<n-3;i++)
    			for (i1=0;i1<n-(i+1)-2;i1++)
    			for (i2=0;i2<n-i-i1-3;i2++)
    			for (i3=0;i3<n-i1-i2-i-3;i3++)
    			{
    				s=(1<<(i+i1+i2+i3+3))+(1<<(i1+i2+i3+2))+(1<<(i2+i3+1))+(1<<i3);
    				sta[++t]=s;
    			}	
    		}
    		else if (m==5)
    		{
    			for (i=0;i<n-3;i++)
    			for (i1=0;i1<n-(i+1)-2;i1++)
    			for (i2=0;i2<n-i-i1-3;i2++)
    			for (i3=0;i3<n-i1-i2-i-4;i3++)
    			for (i4=0;i4<n-i1-i2-i3-i-4;i4++)
    			{
    				s=(1<<(i+i1+i2+i3+i4+4))+(1<<(i1+i2+i3+i4+3))+(1<<(i2+i3+i4+2))+(1<<(i3+i4+1))+(1<<(i4));
    				sta[++t]=s;
    			}	
    		}
    		else
    		{
    			for (i=0;i<n-3;i++)
    			for (i1=0;i1<n-(i+1)-2;i1++)
    			for (i2=0;i2<n-i-i1-3;i2++)
    			for (i3=0;i3<n-i1-i2-i-4;i3++)
    			for (i4=0;i4<n-i1-i2-i3-i-5;i4++)
    			for (i5=0;i5<n-i-i1-i2-i3-i4-5;i5++)
    			{
    				s=(1<<(i+i1+i2+i3+i4+i5+5))+(1<<(i1+i2+i3+i4+i5+4))+(1<<(i2+i3+i4+i5+3))+(1<<(i3+i4+i5+2))+(1<<(i4+i5+1))+(1<<i5);
    				sta[++t]=s;
    			}	
    		}
    		/*cout<<t<<endl;
    		for (i=1;i<=t;i++)
    			cout<<sta[i]<<endl;*/
    		int ss[50],ans=0;
    		memset(ss,0,sizeof(ss));
    		for (i=1;i<=t;i++)
    		{
    			map<int,int>mp;
    			int l=0;
    			for (j=0;j<n;j++)
    				if ((1<<j) & sta[i])
    					ss[l++]=j;        //序列出来了  cout<<ss<<endl;
    			sort(ss,ss+l);
    			do
        		{
            		/*for (i=0;i<m;i++)
            			printf("%d ",a[ss[i]]);
            		cout<<endl;*/
            		mp.clear();
            		int s1[50];
            		memset(s1,0,sizeof(s1));
            		for (i1=0;i1<m;i1++)
            		{
            			s1[i1]=s1[i1+m]=a[ss[i1]];
            			mp[s1[i1]]=1;
            		}
            		for (i1=0;i1<m;i1++)
            		{
            			int h=s1[i1];
            			for (j=i1+1;j<i1+m;j++)
            			{
            				h=h^s1[j];
            				mp[h]=1;
            			}
            		}
            		int h=L;
            		while (mp[h]) h++;
            		if (h!=L && h-1>ans) ans=h-1; 
        		}while (next_permutation(ss, ss+l));
    		}
    		cout<<ans<<endl;
    	}
    	return 0;
    }



  • 相关阅读:
    led呼吸灯
    定时器中断
    npgsql
    中断
    PAT (Advanced Level) 1128~1131:1128N皇后 1129 模拟推荐系统(set<Node>优化) 1130 中缀表达式
    PAT (Advanced Level) 1132~1135:1132 模拟 1133模拟(易超时!) 1134图 1135红黑树
    PAT (Advanced Level) 1136~1139:1136模拟 1137模拟 1138 前序中序求后序 1139模拟
    PAT (Advanced Level) 1140~1143:1140模拟 1141模拟 1142暴力 1143 BST+LCA
    PAT (Advanced Level) 1144~1147:1145Hash二次探查 1146拓扑排序 1147堆
    python实现http接口测试
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4214100.html
Copyright © 2011-2022 走看看