首页 > 其他分享 >POJ-1143

POJ-1143

时间:2023-04-28 17:02:10浏览次数:29  
标签:std 1143 删除 k1 ..... POJ include

 

给定一个序列,轮到谁,取出一个数k删除,并删除i*k(i=1,2,3,.....),

设k1为已经删除的数,同时删除k1*i+k*j,(i=1,2,3,.....;j同上 ),轮到谁没数删除时谁就输了。。

 

求先手取数 可以取那些数字 ,能保证获胜

 

#include<iostream>
#include <cstring>
#include <algorithm>
#include <iomanip>
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(0);
using namespace std ;
const int N =(1<<20)+20;
 int f[N] ;
 int b[N]; 
 bool dfs(int s,int x){
 	s-=(1<<x) ;
 	for(int i=2;i+x<=20;i++)
 		if ( !((1<<i)&s) && (1<<(i+x))&s )
 			s-=(1<<(i+x));
 			
 	if(f[s]>0) return 1 ;
 	if(f[s]<0) return 0;
 	
 	for(int i=2;i<=20;i++)
 		if( (1<<i)&s&&!dfs(s,i)){
 			return f[s]=1 ;
 		}
 	
 	f[s]=-1 ;
 	return 0 ;
 }
 signed main(){
	int n,v,k,cnt=1,flag=0;
	while (cin>>n&&n){
		k=0;
		if (flag)
			cout<<endl;
		memset(f,0,sizeof f);
		f[0]=-1;
		int ans=0;
		for (int i=0;i<n;i++){
			cin>>v;
			ans+=(1<<v);
		}
		for (int i=2;i<=20;i++)
			if(((1<<i)&ans)&&!dfs(ans,i))
				b[k++]=i;
		sort(b,b+k);
		k=unique(b,b+k)-b;
		
		cout<<"Test Case #"<<cnt++<<endl;
		if (k)
		{
			cout<<"The winning moves are: "; 
			for (int i=0;i<k;i++)
				cout<<b[i] << ((i==k-1)?"\n":" ");
		}
		else 
			cout<<"There's no winning move."<<endl;
		flag=1;
	}
	return 0;
} 

 
 

 

标签:std,1143,删除,k1,.....,POJ,include
From: https://www.cnblogs.com/towboa/p/17362630.html

相关文章

  • poj 2584 T-Shirt Gumbo 二分匹配
    T-ShirtGumboTimeLimit: 1000MS MemoryLimit: 65536KTotalSubmissions: 2935 Accepted: 1376DescriptionBoudreauxandThibodeauxarestudentvolunteersforthisyear'sACMSouthCentralRegion'sprogrammingcontest.Oneoftheirdutiesis......
  • POJ 3352 Road Construction 边双联通分量
    题目:http://poj.org/problem?id=3352题意:加上最少的边,使得改造后的图中去掉任意一条边后图依然连通,题中任意两个点之间不会有重边思路:删掉任意一条边图依然连通,意味着任意两点间有至少两条通路。对于边双连通分量内的任意两点,至少会有两条通路,所以求边双连通分量,缩点,求出度为1的点......
  • POJ - 3764 XOR&&dfs 01字典树
    Inanedge-weightedtree,thexor-lengthofapathpisdefinedasthexorsumoftheweightsofedgesonp:{xor}length§=\oplus{e\inp}w(e)⊕isthexoroperator.Wesayapaththexor-longestpathifithasthelargestxor-length.Givenanedge-weigh......
  • POJ - 3614 贪心
    Toavoidunsightlyburnswhiletanning,eachoftheC(1≤C≤2500)cowsmustcoverherhidewithsunscreenwhenthey’reatthebeach.CowihasaminimumandmaximumSPFrating(1≤minSPFi≤1,000;minSPFi≤maxSPFi≤1,000)thatwillwork.Ifthe......
  • 【DP】LeetCode 1143. 最长公共子序列
    题目链接1143.最长公共子序列思路分析动态规划题目的时候只需要考虑最后一个阶段,因为所有的阶段转化都是相同的,考虑最后一个阶段容易发现规律在数组的动态规划问题中,一般dp[i]都是表示以nums以前i个元素组成(即nums[i-1])的状态;dp[i][j]分别表示以nums1前i个元素......
  • POJ 1502 MPI Maelstrom(最短路)
    MPIMaelstromTimeLimit: 1000MS MemoryLimit: 10000KTotalSubmissions: 5476 Accepted: 3409DescriptionBIThasrecentlytakendeliveryoftheirnewsupercomputer,a32processorApolloOdysseydistributedsharedmemorymachinewithahierarchica......
  • POJ 2442 Sequence
    F- SequenceTimeLimit:6000MS     MemoryLimit:65536KB     64bitIOFormat:%I64d&%I64uSubmit Status Practice POJ2442DescriptionGivenmsequences,eachcontainsnnon-negativeinteger.Nowwemayselectonenumber......
  • POJ3984 迷宫问题(BFS 记忆路径)
    迷宫问题TimeLimit:1000MS     MemoryLimit:65536KB     64bitIOFormat:%I64d&%I64uSubmit Status Practice POJ3984SystemCrawler (2014-09-11)Description定义一个二维数组: intmaze[5][5]={0,1,0,0......
  • POJ 1789 Truck History
    TruckHistoryTimeLimit:2000MS     MemoryLimit:65536KB     64bitIOFormat:%I64d&%I64uSubmit Status Practice POJ1789DescriptionAdvancedCargoMovement,Ltd.usestrucksofdifferenttypes.Sometrucksareused......
  • POJ--3050 Hopscotch(暴搜)
    记录21:362023-4-16http://poj.org/problem?id=3050reference:《挑战程序设计竞赛(第2版)》第二章练习题索引p135DescriptionThecowsplaythechild'sgameofhopscotchinanon-traditionalway.Insteadofalinearsetofnumberedboxesintowhichtohop,thec......