TC SRM 670 div2 Treestart

题目大意:

一个树状的棋盘,A,B两种棋子。初始时没有棋子重合,每一轮AB轮流移动任意个(包括不移动)自己的棋子,可以重合。如果某一时刻一格子上同时存在A和B两种棋子,则B获胜。A尽量使游戏进行的总轮数最多,B尽量在最少的轮数获胜(B 一定能获胜),输出最少轮数。

解题思路:

单独考虑A的每个棋子,每次分别扩展并跟新A和B能到的格子,如果A能到的格子中没有B不能到的,那么B胜利。

由于只有50个点,可以用状态压缩来让代码变得更加优美一点~!

using namespace std;

vector<int>G[60];
typedef unsigned long long ULL;
class Treestrat
{
public:
	int len;
	ULL exspand(ULL mask)
	{
		ULL tmp = 0;
		for(int i = 0; i < len; i++)if(mask&(1ULL<<i))
		{
			tmp = tmp | (1ULL<<i);
			for(int j = 0, l = G[i].size(); j < l; j++)
			{
				int to = G[i][j];
				tmp = tmp | (1ULL << to);
			}
		}
		return tmp;
	}
	int getans(ULL ma, ULL mb)
	{
		int res = 0;
		while(ma)
		{
			res++;
			ma = exspand(ma);
			mb = ~(exspand(~mb));
			ma = mb & ma;
		}
		return res;
	}
	int roundcnt(vector <int> tree, vector <int> A, vector <int> B)
	{
		len = tree.size() + 1;
		for(int i = 1; i < len; i++)
		{
			G[i].push_back(tree[i-1]);
			G[tree[i-1]].push_back(i);
		}
		ULL maskb = 0;
		for(int i = 0, l = B.size(); i < l; i++)
			maskb ^= (1LL << B[i]);
		maskb = ~maskb;
		int ans = 100;
		for(int i = 0, l = A.size(); i < l; i++)
		{
			ans = min(ans, getans(1LL << A[i], maskb));
		}
		return ans;
	}
};

  

时间: 2024-10-03 22:49:45

TC SRM 670 div2 Treestart的相关文章

TC SRM 665 DIV2 A LuckyXor 暴力

LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive integer consisting of only the digits 4 and 7.Given an int a, return an int b strictly greater than a, such that a XOR b is a lucky number. (See Notes fo

TC SRM 663 div2 A ChessFloor 暴力

ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a square room. The floor of the room is an N times N grid of unit square tiles. Each tile has some color. You are given the current colors of all tiles in a

TC SRM 663 div2 B AABB 逆推

AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many English words only use the letters A and B. Examples of such words include "AB" (short for abdominal), "BAA" (the noise a sheep makes), &

TC SRM 664 div2 AB

#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; class BearCheats{ public: string eyesight(int A, int B){ char t[256]; string s1; sprintf(t, "%d", A); s1 = t; string s2; cha

TC SRM 664 div2 B BearPlaysDiv2 bfs

BearPlaysDiv2 Problem Statement    Limak is a little bear who loves to play. Today he is playing by moving some stones between three piles of stones. Initially, the piles contain A, B, and C stones, respectively. Limak's goal is to produce three equa

tc srm 636 div2 500

100的数据直接暴力就行,想多了... ac的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <algorithm> 7 #include <vector> 8 #define LL __int64 9 const int maxn =

SRM 670 div2 ABC

A Cdgame brute force... B Drbalance 贪心,每次选最前面的-变成+,相当于后面所有的负值+2. C Treestrat 考虑集中去抓一个Red Token,以这个Token为根把树提起来,以B中Token为的根的子树是走不到,(树形很重要) 而且走不到的结点只会越来越多.求出B中结点到达树上任意点v的最短距离D[v],当且仅当Red Token到点v的距离小于D[v]时候 ,才可以向v走.选出一个最大的D[v]作为抓这个Red Token时的答案.所有Red T

TC SRM 636 Div2 C ChocolateDividingHard 二分

先把行合并,然后二分一下最小值就好. // BEGIN CUT HERE // END CUT HERE #line 5 "ChocolateDividingHard.cpp" #include <cstdlib> #include <cctype> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> #include

SRM 630 DIV2

SRM 630 DIV2 第一次TC,本来以为AK了,结果1000分还是被系统cha掉了,不过倒是也cha掉了房间其他人赚了不少 A:字符串长度才50,直接简单的模拟即可 B:结点个数才10,先做一边floyd,找出两两之间路径,然后暴力枚举选哪些点,判断可不可以,如果可以的话,记录下最大个数 C:一开始的做法是,构造出rank数组后,对于连续的一段,都放a,然后最后一个放b即可,以为这样构造出来的肯定是字典序最小的,结果被系统cha掉了. 正确做法:一开始先构造出sa数组,暴力枚举每个位置,非