ACM:Sagittarius's Trial(1)

A. Fox And Snake
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.

A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then it’s body extends to (1, m), then goes down 2 rows to (3, m), then goes left to (3, 1) and so on.

Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters (’.’) and the snake cells should be filled with number signs (’#’).

Consider sample tests in order to understand the snake pattern.
Input

The only line contains two integers: n and m (3 ≤ n, m ≤ 50).

n is an odd number.
Output

Output n lines. Each line should contain a string consisting of m characters. Do not output spaces.
Examples
Input
Copy

3 3

Output
Copy

…#

Input
Copy

3 4

Output
Copy

…#

Input
Copy

5 3

Output
Copy

…#

#…

Input
Copy

9 9

Output
Copy

#########
…#
#########
#…
#########
…#
#########
#…
#########

AC:

#include<stdio.h>
int main()
{
	int m = 0,n = 0,i = 0,j = 0;
	
	scanf("%d %d", &m,&n);
	for(i=0;i<m;i++) 
	{
		if(i%2==0)
		{
			for(j=0;j<n;j++)
				printf("#");
		}
		else 
		{
			if((i-1)%4==2)
				printf("#");
			for(j=0;j<n-1;j++) 
				printf(".");
			if((i-1)%4==0) 
				printf("#");
		}
		printf("\n");
	}
	return 0;
}

B. Buttons
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you’ve guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.

Consider an example with three buttons. Let’s say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you’ve got two pressed buttons, you only need to press button 1 to open the lock.

Manao doesn’t know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he’s got to push a button in order to open the lock in the worst-case scenario.
Input

A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.
Output

In a single line print the number of times Manao has to push a button in the worst-case scenario.
Examples
Input
Copy

2

Output
Copy

3

Input
Copy

3

Output
Copy

7

Note

Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.

AC:

#include<stdio.h>
int main()
{
	int total = 0,i = 0,ans = 0;

	scanf("%d",&total);
	
	for(i=1;i<=total;i++)
		ans+=1+(total-i)*i;

	printf("%d\n",ans);
	return 0;
}

FatMouse and Cheese
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15299 Accepted Submission(s): 6463

Problem Description
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <= p < n and 0 <= q < n. At each grid location Fatmouse has hid between 0 and 100 blocks of cheese in a hole. Now he’s going to enjoy his favorite food.

FatMouse begins by standing at location (0,0). He eats up the cheese where he stands and then runs either horizontally or vertically to another location. The problem is that there is a super Cat named Top Killer sitting near his hole, so each time he can run at most k locations to get into the hole before being caught by Top Killer. What is worse – after eating up the cheese at one location, FatMouse gets fatter. So in order to gain enough energy for his next run, he has to run to a location which have more blocks of cheese than those that were at the current hole.

Given n, k, and the number of blocks of cheese at each grid location, compute the maximum amount of cheese FatMouse can eat before being unable to move.

Input
There are several test cases. Each test case consists of

a line containing two integers between 1 and 100: n and k
n lines, each with n numbers: the first line contains the number of blocks of cheese at locations (0,0) (0,1) … (0,n-1); the next line contains the number of blocks of cheese at locations (1,0), (1,1), … (1,n-1), and so on.
The input ends with a pair of -1’s.

Output
For each test case output in a line the single integer giving the number of blocks of cheese collected.

Sample Input

3 1
1 2 5
10 11 6
12 12 7
-1 -1

Sample Output

37

Source
Zhejiang University Training Contest 2001

AC:

#include<stdio.h>
#include<string.h>
#include<iostream> 
using namespace std;
int n = 0,k = 0,a[200][200] = {0},dp[200][200]={0};
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
int dfs(int x,int y)
{
	int xx = 0,yy = 0;
	if(dp[x][y]) 
		return dp[x][y];
	int ans=0;
	for(int i=0;i<4;i++)
	{
		for(int j=1;j<=k;j++)
		{
			xx=x+j*dx[i];
			yy=y+j*dy[i];
			if(xx>=0&&xx<n&&yy>=0&&yy<n&&a[xx][yy]>a[x][y])
				if(ans<dfs(xx,yy)) ans=dfs(xx,yy);
		}
	}
	dp[x][y]=ans+a[x][y];
	return dp[x][y];
}
int main()
{

	while(scanf("%d%d",&n,&k))
	{
		if(n==-1&&k==-1) 
		break;
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin >> a[i][j];
			dp[i][j]=0;
		}
	}
	dfs(0,0);
	printf("%d\n",dp[0][0]);
	}
	return 0;
}

What Are You Talking About
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 29606 Accepted Submission(s): 10125

Problem Description
Ignatius is so lucky that he met a Martian yesterday. But he didn’t know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book into English. Can you help him?

Input
The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string “START”, this string should be ignored, then some lines follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian’s language. A line with a single string “END” indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string “START”, this string should be ignored, then an article written in Martian’s language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new word into your translation, if you can’t find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(’ ‘), tab(’\t’), enter(’\n’) and all the punctuation should not be translated. A line with a single string “END” indicates the end of the book part, and that’s also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.

Output
In this problem, you have to output the translation of the history book.

Sample Input

START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i’m fiwo riwosf.
i fiiwj fnnvk!
END

Sample Output

hello, i’m from mars.
i like earth!

Hint

Huge input, scanf is recommended.

Author
Ignatius.L

AC:

#include<algorithm>
#include<string> 
#include<cstdlib> 

#include<iostream>
#include<string>
#include<map>
using namespace std;
map<string,string> MMsee;

int main()
{
	string a,b;
	cin>>a;//"START"
	
	while(cin>>a && a!="END")
	{
		 cin>>b;
		 MMsee[b] = a;
	}

	cin>>b;//"START"
	getchar();
	char temp[3005];
	while(1)
	{
		gets(temp);
		if(strcmp(temp,"END") == 0 )
			 break;
		
		int i = 0,len = 0;
		len = strlen(temp);
		b = "";
		for(i=0;i<len;i++)
		 {
			if(!(temp[i]>='a' && temp[i]<='z'))
			{
				if(MMsee[b]!="")
					cout<<MMsee[b];
				 else
					 cout<<b;
				 b="";
				cout<<temp[i];
			 }
			else 
			   b+=temp[i];
		 }
		cout<<endl;
	 }

	return 0;
 } 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值