首页 > 代码库 > acm_icpc网络赛第三站:西安赛区

acm_icpc网络赛第三站:西安赛区

chp居然没来。。然后我跟zmc鼓捣了一下午。。出了3题 有一道貌似是DP水题。。然后我俩都不会dp。。A题水题不说了,E题博弈论模板。。然后我俩也都不会博弈论。。现场找的模板。。F题无脑BFS。。一开始看成计算几何了没敢做sad。。

A题:

Post Robot

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 57    Accepted Submission(s): 51


Problem Description
DT is a big fan of digital products. He writes posts about technological products almost everyday in his blog.

But there is such few comments of his posts that he feels depressed all the day. As his best friend and an excellent programmer, DT asked you to help make his blog look more popular. He is so warm that you have no idea how to refuse. But you are unwilling to read all of his boring posts word by word. So you decided to write a script to comment below his posts automatically.

After observation, you found words “Apple” appear everywhere in his posts. After your counting, you concluded that “Apple”, “iPhone”, “iPod”, “iPad” are the most high-frequency words in his blog. Once one of these words were read by your smart script, it will make a comment “MAI MAI MAI!”, and go on reading the post. 

In order to make it more funny, you, as a fan of Sony, also want to make some comments about Sony. So you want to add a new rule to the script: make a comment “SONY DAFA IS GOOD!” when “Sony” appears.
 

Input
A blog article described above, which contains only printable characters(whose ASCII code is between 32 and 127), CR(ASCII code 13, ‘\r’ in C/C++), LF(ASCII code 10, ‘\n’ in C/C++), please process input until EOF. Note all characters are case sensitive.

The size of the article does not exceed 8KB.
 

Output
Output should contains comments generated by your script, one per line.
 

Sample Input
Apple bananaiPad lemon ApplepiSony 233 Tim cook is doubi from Apple iPhoneipad iPhone30 is so biiiiiiig Microsoft makes good App.
 

Sample Output
MAI MAI MAI! MAI MAI MAI! MAI MAI MAI! SONY DAFA IS GOOD! MAI MAI MAI! MAI MAI MAI! MAI MAI MAI!
水 1Y;

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
#define LL long long
char s[1000010];
int main()
{
	while(gets(s))
	{
		int len=strlen(s);
		for(int i=0;i<len;i++)
			if(!strncmp(s+i,"Apple",5))
			puts("MAI MAI MAI!");
		    else if(!strncmp(s+i,"iPhone",6))
			puts("MAI MAI MAI!");
			else if(!strncmp(s+i,"iPod",4))
			puts("MAI MAI MAI!");
			else if(!strncmp(s+i,"iPad",4))
			puts("MAI MAI MAI!");
			else if(!strncmp(s+i,"Sony",4))
			puts("SONY DAFA IS GOOD!");
	}
	return 0;
}

E题:

Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 55    Accepted Submission(s): 41


Problem Description
Here is a game for two players. The rule of the game is described below: 

● In the beginning of the game, there are a lot of piles of beads.

● Players take turns to play. Each turn, player choose a pile i and remove some (at least one) beads from it. Then he could do nothing or split pile i into two piles with a beads and b beads.(a,b > 0 and a + b equals to the number of beads of pile i after removing) 

● If after a player‘s turn, there is no beads left, the player is the winner.

Suppose that the two players are all very clever and they will use optimal game strategies. Your job is to tell whether the player who plays first can win the game.
 

Input
There are multiple test cases. Please process till EOF.

For each test case, the first line contains a postive integer n(n < 105) means there are n piles of beads. The next line contains n postive integer, the i-th postive integer ai(ai < 231) means there are ai beads in the i-th pile.
 

Output
For each test case, if the first player can win the game, ouput "Win" and if he can‘t, ouput "Lose"
 

Sample Input
1 1 2 1 1 3 1 2 3
 

Sample Output
Win Lose Lose

博弈论 尼姆博奕(Nimm Game)

指的是这样的一个博弈游戏,目前有任意堆石子,每堆石子个数也是任意的,双方轮流从中取出石子,规则如下:
1)每一步应取走至少一枚石子;每一步只能从某一堆中取走部分或全部石子;
2)如果谁取到最后一枚石子就胜。
也就是尼姆博弈(Nimm Game)。

结论:假设有n堆物品,每堆物品有a[i]件,若a[0]^a[1]^a[2]^........a[n-1]!=0 先手必胜,否则必败。

#include <cstdio>
using namespace std;
int main()
{
	int n,t,x;
	while(~scanf("%d",&n))
	{
		scanf("%d",&t);--n;
		while(n--)
		{
			scanf("%d",&x);t^=x;
		}
		if(t)puts("Win");
		else puts("Lose");
	}
	return 0;
}

F题:

Dice

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 93    Accepted Submission(s): 54


Problem Description
There are 2 special dices on the table. On each face of the dice, a distinct number was written. Consider a1.a2,a3,a4,a5,a6 to be numbers written on top face, bottom face, left face, right face, front face and back face of dice A. Similarly, consider b1.b2,b3,b4,b5,b6 to be numbers on specific faces of dice B. It’s guaranteed that all numbers written on dices are integers no smaller than 1 and no more than 6 while ai ≠ aj and bi ≠ bj for all i ≠ j. Specially, sum of numbers on opposite faces may not be 7.

At the beginning, the two dices may face different(which means there exist some i, ai ≠ bi). Ddy wants to make the two dices look the same from all directions(which means for all i, ai = bi) only by the following four rotation operations.(Please read the picture for more information)


Now Ddy wants to calculate the minimal steps that he has to take to achieve his goal.
 

Input
There are multiple test cases. Please process till EOF. 

For each case, the first line consists of six integers a1,a2,a3,a4,a5,a6, representing the numbers on dice A. 

The second line consists of six integers b1,b2,b3,b4,b5,b6, representing the numbers on dice B.
 

Output
For each test case, print a line with a number representing the answer. If there’s no way to make two dices exactly the same, output -1.
 

Sample Input
1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 5 6 4 3 1 2 3 4 5 6 1 4 2 5 3 6
 

Sample Output
0 3 -1

六维BFS。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
struct node
{
	int a[7],step;
};
bool vis[7][7][7][7][7][7];
int s[7],e[7];
void bfs()
{
	queue <node> Q;
	node t,f;
	for(int i=1;i<7;i++)
	t.a[i]=s[i];t.step=0;
	vis[t.a[1]][t.a[2]][t.a[3]][t.a[4]][t.a[5]][t.a[6]]=1;
	Q.push(t);
	while(!Q.empty())
	{
		f=Q.front();Q.pop();
		if(f.a[1]==e[1]&&f.a[2]==e[2]&&f.a[3]==e[3]&&f.a[4]==e[4]&&f.a[5]==e[5]&&f.a[6]==e[6])
		{
			printf("%d\n",f.step);
			return ;
		}
		t.step=f.step+1;
		//left
		t.a[1]=f.a[4];t.a[2]=f.a[3];t.a[3]=f.a[1];t.a[4]=f.a[2];t.a[5]=f.a[5];t.a[6]=f.a[6];
		if(!vis[t.a[1]][t.a[2]][t.a[3]][t.a[4]][t.a[5]][t.a[6]])
		{
			vis[t.a[1]][t.a[2]][t.a[3]][t.a[4]][t.a[5]][t.a[6]]=1;
			Q.push(t);
		}
		//right
		t.a[1]=f.a[3];t.a[2]=f.a[4];t.a[3]=f.a[2];t.a[4]=f.a[1];t.a[5]=f.a[5];t.a[6]=f.a[6];
		if(!vis[t.a[1]][t.a[2]][t.a[3]][t.a[4]][t.a[5]][t.a[6]])
		{
			vis[t.a[1]][t.a[2]][t.a[3]][t.a[4]][t.a[5]][t.a[6]]=1;
			Q.push(t);
		}
		//front
		t.a[1]=f.a[6];t.a[2]=f.a[5];t.a[3]=f.a[3];t.a[4]=f.a[4];t.a[5]=f.a[1];t.a[6]=f.a[2];
		if(!vis[t.a[1]][t.a[2]][t.a[3]][t.a[4]][t.a[5]][t.a[6]])
		{
			vis[t.a[1]][t.a[2]][t.a[3]][t.a[4]][t.a[5]][t.a[6]]=1;
			Q.push(t);
		}
		//back
		t.a[1]=f.a[5];t.a[2]=f.a[6];t.a[3]=f.a[3];t.a[4]=f.a[4];t.a[5]=f.a[2];t.a[6]=f.a[1];
		if(!vis[t.a[1]][t.a[2]][t.a[3]][t.a[4]][t.a[5]][t.a[6]])
		{
			vis[t.a[1]][t.a[2]][t.a[3]][t.a[4]][t.a[5]][t.a[6]]=1;
			Q.push(t);
		}
	}
    puts("-1");
}
int main()
{
	while(~scanf("%d",&s[1]))
	{
		memset(vis,0,sizeof(vis));
		for(int i=2;i<7;i++)
			scanf("%d",&s[i]);
		for(int i=1;i<7;i++)
			scanf("%d",&e[i]);
		bfs();
	}
	return 0;
}


acm_icpc网络赛第三站:西安赛区