2013年福建省赛ACM题目

102 篇文章 0 订阅
99 篇文章 0 订阅

Link:http://acm.fzu.edu.cn/problem.php?pid=2146

Problem:

Problem 2146 Easy Game

Accept: 532    Submit: 728
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

Fat brother and Maze are playing a kind of special (hentai) game on a string S. Now they would like to count the length of this string. But as both Fat brother and Maze are programmers, they can recognize only two numbers 0 and 1. So instead of judging the length of this string, they decide to judge weather this number is even.

 Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case contains a line describe the string S in the treasure map. Not that S only contains lower case letters.

1 <= T <= 100, the length of the string is less than 10086

 Output

For each case, output the case number first, and then output “Odd” if the length of S is odd, otherwise just output “Even”.

 Sample Input

4wellthisisthesimplestprobleminthiscontest

 Sample Output

Case 1: EvenCase 2: OddCase 3: OddCase 4: Odd

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	string s;
	int cas,T;
	while(cin>>T)
	{
		for(cas=1;cas<=T;cas++)
		{
			cin>>s;
			if(s.length()%2==0)
			cout<<"Case "<<cas<<": Even"<<endl;
			else
			cout<<"Case "<<cas<<": Odd"<<endl;
		}
	}
	return 0;
}


Link:http://acm.fzu.edu.cn/problem.php?pid=2147


Problem:

 Problem 2147 A-B Game

Accept: 650    Submit: 1563
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

Fat brother and Maze are playing a kind of special (hentai) game by two integers A and B. First Fat brother write an integer A on a white paper and then Maze start to change this integer. Every time Maze can select an integer x between 1 and A-1 then change A into A-(A%x). The game ends when this integer is less than or equals to B. Here is the problem, at least how many times Maze needs to perform to end this special (hentai) game.

 Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case contains two integers A and B described above.

1 <= T <=100, 2 <= B < A < 100861008610086

 Output

For each case, output the case number first, and then output an integer describes the number of times Maze needs to perform. See the sample input and output for more details.

 Sample Input

25 310086 110

 Sample Output

Case 1: 1Case 2: 7

import java.text.*;
import java.util.*;
import java.math.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner cin=new Scanner(System.in);
		BigInteger a,b,cnt,x;
		int cas,T;
		while(cin.hasNext())
		{
			T=cin.nextInt();
			for(cas=1;cas<=T;cas++)
			{
				a=cin.nextBigInteger();
				b=cin.nextBigInteger();
				cnt=BigInteger.ZERO;
				while(a.compareTo(b)>0)
				{
					x=a.add(BigInteger.ONE).divide(BigInteger.valueOf(2)).subtract(BigInteger.ONE);
					a=a.subtract(x);
					cnt=cnt.add(BigInteger.ONE);
				}
				System.out.println("Case "+cas+": "+cnt);
			}
		}
	}
}


Link:http://acm.fzu.edu.cn/problem.php?pid=2151


Problem:

Problem 2151 OOXX Game

Accept: 569    Submit: 874
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, there are N*M coins in this board with two symbol “O” or “X”. Then they take turns to choose a grid with symbol “O” and change it into “X”. The game ends when all the symbols in the board are “X”, and the one who cannot play in his (her) turns loses the game. Fat brother and Maze like this kind of OOXX game very much and play it day and night. They don’t even need a little rest after each game!

Here's the problem: Who will win the game if both use the best strategy? You can assume that Maze always goes first.

 Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case contains two integers N and M indicate the size of the board. Then goes N line, each line with M character shows the state of the board.

1 <= T <=100, 1 <= n <=100, 1 <= m <=100

 Output

For each case, output the case number first, and then output the winner’s name, either Fat brother or Maze. See the sample input and output for more details.

 Sample Input

31 4OXXX2 4OOXXOOXX1 2XX

 Sample Output

Case 1: MazeCase 2: Fat brotherCase 3: Fat brother

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
char b[111][111];
int n,m;
int main()
{
	int cnt,i,j,T,cas;
	while(~scanf("%d",&T))
	{
		for(cas=1;cas<=T;cas++)
		{
			scanf("%d%d",&n,&m);
			cnt=0;
			for(i=0;i<n;i++)
			{
				scanf("%s",b[i]);
				for(j=0;j<m;j++)
				{
					if(b[i][j]=='O')
					cnt++;
				}
			}
			if(cnt%2==1)
			printf("Case %d: Maze\n",cas);
			else
			printf("Case %d: Fat brother\n",cas);
		}
	}
	return 0;
}


Link:http://acm.fzu.edu.cn/problem.php?pid=2150


Problem:

 Problem 2150 Fire Game

Accept: 452    Submit: 1793
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start to fire all the grass. Firstly they choose two grids which are consisting of grass and set fire. As we all know, the fire can spread among the grass. If the grid (x, y) is firing at time t, the grid which is adjacent to this grid will fire at time t+1 which refers to the grid (x+1, y), (x-1, y), (x, y+1), (x, y-1). This process ends when no new grid get fire. If then all the grid which are consisting of grass is get fired, Fat brother and Maze will stand in the middle of the grid and playing a MORE special (hentai) game. (Maybe it’s the OOXX game which decrypted in the last problem, who knows.)

You can assume that the grass in the board would never burn out and the empty grid would never get fire.

Note that the two grids they choose can be the same.

 Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case contains two integers N and M indicate the size of the board. Then goes N line, each line with M character shows the board. “#” Indicates the grass. You can assume that there is at least one grid which is consisting of grass in the board.

1 <= T <=100, 1 <= n <=10, 1 <= m <=10

 Output

For each case, output the case number first, if they can play the MORE special (hentai) game (fire all the grass), output the minimal time they need to wait after they set fire, otherwise just output -1. See the sample input and output for more details.

 Sample Input

43 3.#.###.#.3 3.#.#.#.#.3 3...#.#...3 3###..##.#

 Sample Output

Case 1: 1Case 2: -1Case 3: 0Case 4: 2

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
using namespace std;
struct node{
	int r;
	int c;
	int t;
}st1,st2,mapp[111];
int d[4][2]={{0,1},{1,0},{-1,0},{0,-1}},vis[11][11];
int n,m,ans,maxt,cnt,cnt1;
char map[11][11];

bool cango(int r,int c)
{
	if(r>=0&&r<n&&c>=0&&c<m)
	return true;
	return false;
}
void dfs(int r,int c)
{
	int ri,ci;
	vis[r][c]=1;
	for(int i=0;i<4;i++)
	{
		ri=r+d[i][0];
		ci=c+d[i][1];
		if(cango(ri,ci)&&!vis[ri][ci]&&map[ri][ci]=='#')
		{
			dfs(ri,ci);
		}
	}
}
int bfs(int r1,int c1,int r2,int c2)
{
	maxt=0;
	queue<node>Q;
	memset(vis,0,sizeof(vis));
	st1.r=r1;
	st2.r=r2;
	st1.c=c1;
	st2.c=c2;
	st1.t=0;
	st2.t=0;
	vis[r1][c1]=1;
	vis[r2][c2]=1;
	Q.push(st1);
	Q.push(st2);
	node now,next;
	while(!Q.empty())
	{
	   now=Q.front();
	   Q.pop();
	   for(int i=0;i<4;i++)
	   {
	   	next.r=now.r+d[i][0];
	   	next.c=now.c+d[i][1];
	   	if(cango(next.r,next.c)&&!vis[next.r][next.c]&&map[next.r][next.c]=='#')
	   	{
	   		vis[next.r][next.c]=1;
	   		next.t=now.t+1;
	   		Q.push(next);
		}
	   }
	 maxt=max(maxt,now.t);
	}
	return maxt;
}
int main()
{
	int T,cas,i,j,k,tem,fg,l;
	while(scanf("%d",&T)==1)
	{
		cas=0;
		while(T--)
		{
			cas++;
		scanf("%d%d",&n,&m);
		cnt=0;
		for(i=0;i<n;i++)
		{
			scanf("%s",map[i]);
			for(j=0;j<m;j++)
			{
				if(map[i][j]=='#')
				{
					cnt++;
					mapp[cnt].r=i;
					mapp[cnt].c=j;
				}
			}
		}
		cnt1=0;
		memset(vis,0,sizeof(vis));
		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++)
			{
				if(!vis[i][j]&&map[i][j]=='#')
				{
					dfs(i,j);
					cnt1++;
				}
			}
		}
		//printf("%d\n",cnt1);
		if(cnt1>=3)
		{
			ans=-1;
		}
		else
		{
			//printf("%d",cnt);
			ans=999999;
			for(i=1;i<=cnt;i++)
			{
				for(j=i;j<=cnt;j++)
				{
					st1=mapp[i];
					st2=mapp[j];
					tem=bfs(st1.r,st1.c,st2.r,st2.c);
					//.printf("%d\n",tem);
					fg=1;
					for(k=0;k<n;k++)
					{
						for(l=0;l<m;l++)
						{
						if(!vis[k][l]&&map[k][l]=='#')
						{
							fg=0;
							break;
						}
					   }
					   if(!fg)
					   break;
					}
					if(fg)
					ans=min(tem,ans);
				}
			}
		}
		printf("Case %d: %d\n",cas,ans);
	  }
	}
}


Link:http://acm.fzu.edu.cn/problem.php?pid=2148


Problem:

 Problem 2148 Moon Game

Accept: 434    Submit: 1223
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consider as a kind of two-dimensional plane. Then Fat brother starts to draw N starts in the sky which we can just consider each as a point. After he draws these stars, he starts to sing the famous song “The Moon Represents My Heart” to Maze.

You ask me how deeply I love you,

How much I love you?

My heart is true,

My love is true,

The moon represents my heart.

But as Fat brother is a little bit stay-adorable(呆萌), he just consider that the moon is a special kind of convex quadrilateral and starts to count the number of different convex quadrilateral in the sky. As this number is quiet large, he asks for your help.

 Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case contains an integer N describe the number of the points.

Then N lines follow, Each line contains two integers describe the coordinate of the point, you can assume that no two points lie in a same coordinate and no three points lie in a same line. The coordinate of the point is in the range[-10086,10086].

1 <= T <=100, 1 <= N <= 30

 Output

For each case, output the case number first, and then output the number of different convex quadrilateral in the sky. Two convex quadrilaterals are considered different if they lie in the different position in the sky.

 Sample Input

240 0100 00 100100 10040 0100 00 10010 10

 Sample Output

Case 1: 1Case 2: 0

思想:

判断是不是凹四边形。

如果四边形有一个点在另外三个点组成的三角形内部,这个四边形就是凹四边形,否则就是凸四边形。

凹四边形内部那个点和其余任意两点可以组成三个三角形,这三个三角形面积的和恰好为外部三个点组成的三角形面积。
根据三角形三个点的二维坐标求三角形面积有个公式:abs(p[a].x * p[b].y + p[c].x * p[a].y + p[b].x * p[c].y - p[c].x * p[b].y - p[a].x * p[c].y - p[b].x * p[a].y) * 0.5。
解题思路

  这题目很简单:给多个不重复坐标点,求不重复的凸四边形个数。而且n最大是30,所以枚举所有四个点的组合。而判断是否构成凸四边的条件是:1:四点组合中要存在两条交叉的直线  2:四点组合中不能存在 “一个点在其他三个点组成的三角形 内部"(本代码选择的方案)。

代码

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #include<stdio.h>  
  2. #include<math.h>  
  3. struct point  
  4. {  
  5.     double x;  
  6.     double y;  
  7. }all[40];  
  8. double area(int a, int b, int c)  
  9. {  
  10.     return fabs(all[b].x*all[a].y - all[c].x*all[a].y - all[a].x*all[b].y + all[c].x*all[b].y + all[a].x*all[c].y - all[b].x*all[c].y) / 2;//求三角形面积  
  11. }  
  12. bool ok(int a, int b, int c, int d)  
  13. {  
  14.     if (area(a, b, c) == (area(a, b, d) + area(a, d, c) + area(d, b, c)))  
  15.         return false;  
  16.     return true;  
  17. }  
  18. int main()  
  19. {  
  20.     int t;  
  21.     scanf("%d", &t);  
  22.     for (int k = 1; k <= t; k++){  
  23.         int n;  
  24.         scanf("%d", &n);  
  25.         for (int i = 0; i < n; i++){  
  26.             scanf("%lf%lf", &all[i].x, &all[i].y);  
  27.         }  
  28.         int ans = 0;  
  29.         printf("Case %d: ", k);  
  30.         for (int i = 0; i < n; i++)  
  31.         for (int j = i + 1; j < n; j++)  
  32.         for (int e = j + 1; e < n; e++)  
  33.         for (int f = e + 1; f < n; f++){  
  34.             if (ok(i, j, e, f) && ok(f, j, e, i) && ok(i, f, e, j) && ok(i, j, f, e)){  
  35.                 ans++;  
  36.             }  
  37.         }  
  38.         printf("%d\n", ans);  
  39.     }  
  40.     return 0;  
  41. }  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林下的码路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值