浙江省赛热身赛之---周赛第一场

Code Formatter

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 33   Accepted Submission(s) : 9
Problem Description

Some companies have special requirements for source code format, and it is also good for programmers to keep consistent code style. You are asked to write a simple code formatter for the company to help the poor programmers.

The first thing you need to do is to check whether the source code contains tabs (represented as the escape character '\t'), since different terminals have different ways to display tabs, it's better not to use them, but replace them with spaces. The code formatter should replace each tab of the source code with 4(four) blank spaces.

Then you need to remove trailing spaces of the source file. Trailing spaces are one or more consecutive whitespaces right before the EOL (end of line, represented as the escape character '\n'), and they usually have no meaning in most programming language, so they can be safely removed.

Input

The input contains multiple test cases!

The first line is an integer N indicating the number of test cases. Each test case is the source which contains not more than 100 lines given to you to format. A single line containing only "##" marks the end of a test case.

Output

For each test case, output a log of the formatter in two lines of the following format:

#A tab(s) replaced #B trailing space(s) removed Where #A is the number of tabs replaced and #B is the number of trailing spaces removed.

Sample Input

2
include <stdio.h>

int main()
{
	int a,b;
	while(scanf("%d %d",&a, &b) != EOF) 
		printf("%d\n",a+b);             
        
}
##

##

Sample Output

4 tab(s) replaced
22 trailing space(s) removed
0 tab(s) replaced
0 trailing space(s) removed

Note

In order to show the whitespaces precisely, all the characters in sample input are underlined. They are not the underscore character.


 

Source

Zhejiang Provincial Programming Contest 2007

code:

#include <iostream>
#include <string>
#include <fstream>
#include <ctype.h>
using namespace std;

int main()
{
//	fstream cin;
//	cin.open("a.txt");
	int testcase;
	cin>>testcase;
	while(testcase--)
	{
		string tar;
		string tmp="a";
		int tab=0,myspace=0;
		while(getline(cin,tar))
		{
			if(tar=="##")
			{
				cout<<tab<<" tab(s) replaced"<<endl;
				cout<<myspace<<" trailing space(s) removed"<<endl;
				break;
			}
			
			for(int j=tar.size()-1;j>=0;j--)
			{
				if(tar[j]==' ')
					{
						myspace++;
						tar.replace(j,tmp.size(),tmp);
					}
				else if(tar[j]=='\t')
					{
						myspace+=4;
						tab++;
						tar.replace(j,tmp.size(),tmp);
					}
				else
					break;
			}
			for(int i=0;i<tar.size();i++)
			{
				if(tar[i]=='\t')
					tab++;
				 
			}
			/*
for(int k=0;k<tar.size();k++)
			{
				if(tar[k]==' '&&tar[k+1]==' '&&tar[k+2]==' '&&tar[k+3]==' ')
				tab++;
				//if(tar[k]!=' '||tar[k]!='	')
				//break;
			}
			*/
			
		
		}
	}
	return 0;
}


Beautiful Meadow

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 32   Accepted Submission(s) : 10
Problem Description


Tom's Meadow
Tom has a meadow in his garden. He divides it into N * M squares. Initially all the squares were covered with grass. He mowed down the grass on some of the squares and thinks the meadow is beautiful if and only if

  1. Not all squares are covered with grass.
  2. No two mowed squares are adjacent.

Two squares are adjacent if they share an edge. Here comes the problem: Is Tom's meadow beautiful now?

Input

The input contains multiple test cases!

Each test case starts with a line containing two integers N, M (1 <= N, M <= 10) separated by a space. There follows the description of Tom's Meadow. There're N lines each consisting of M integers separated by a space. 0(zero) means the corresponding position of the meadow is mowed and 1(one) means the square is covered by grass.

A line with N = 0 and M = 0 signals the end of the input, which should not be processed     

Output

One line for each test case.

Output "Yes" (without quotations) if the meadow is beautiful, otherwise "No"(without quotations).

Sample Input

2 2
1 0
0 1
2 2
1 1
0 0
2 3
1 1 1
1 1 1
0 0

Sample Output

Yes
No
No

 code:

#include<iostream>
#include<string>
using namespace std;
//int dir[4][2]={0,1,0,-1,-1,0,1,0};
int main()
{
    int m,n;
    int map[20][20];
    int flag;
    int T;
    while (cin>>m>>n)
    {
        flag=0;
        T=0;
        if (m==0||n==0) break;
       
 
        
             for (int i=0;i<=m+1;i++)       
            for (int j=0;j<=n+1;j++)
                map[i][j]=1;
        for (int i=1;i<=m;i++)
        {
            for (int j=1;j<=n;j++)
            {
                cin>>map[i][j];
                if (map[i][j]==0)
                {
                    T=1;
                }
            }
        }

        if (T==1)
        {
            for (int i=1;i<=m;i++)
                for (int j=1;j<=n;j++)
                {

                    if (map[i][j]==0)
                        if (map[i][j+1]==0||map[i-1][j]==0||map[i+1][j]==0||map[i][j-1]==0)
                        {
                            flag=1;
                            break;
                        }
                }

            if (flag==1)
                cout<<"No"<<endl;
            else
                cout<<"Yes"<<endl;
        }

        else
            cout<<"No"<<endl;




    }
    return 0;
}//将图的周围都设置成为1   
//1002   Beautiful Meadow zoj 2850 
 
 


 

 Google Map

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 4   Accepted Submission(s) : 2
Problem Description

GoogleMap is a useful tool and most of you should be familiar with it. As the best hacker in the world, Jack is planning to retrieve all the data on the GoogleMap server. But he soon gives up because the total amount of data exceeds 1000T bytes! But he has learnt the way in which Google stores their data on the server, and he turns to download only the parts that he's interested in. Here is the representation of the data that Jack has found:

First of all, you should know the basic background knowledge of GIS (Geography Information System). In GoogleMap, the whole world is represented in a whole flat image transformed from the surface of the earth by Mercator projection. The Mercator projection is a map projection which is widely used for navigation. The following equations place the x-axis of the projection on the equator (from West to East) and the y-axis at longitude 0 (from South to North)

  • x = longitude * pi / 180;
  • y = ln(tan(pi / 4 + (latitude * pi / 180) / 2))

Here, the latitude is between [-85, 85] (negative for South) and the longitude is between [-180, 180] (negative for West)  The left of the map image is W180 and the right is E180. The top of the map image is N85 and the bottom is S85. The maps have different levels. In the first level, the whole image consists of only one tile with tag name "t". For each tile in one level, it will be clipped into 4 equally sized parts and magnified by 2 in the next level.

And the new tag name for the tiles in the next level will be the tag of their parent tile followed by the identifier of the clip area in the parent tile. (that is, q for left-top, r for right-top, t for left-bottom, s for right-bottom) For example:

So there will be 4L tiles in level L (Assume the first level is labeled as level 0). More interestingly, the filename of the tile on the server is just the tag name. Although Jack is very genius, he doesn't know any programming language, so he turns to you for writing a tool to generate the tags for him.

Input

The input contains multiple test cases!

In each case, there will be three numbers. The first two are the coordinates that indicate the longitude and latitude of the interested location, and the third is the level number required by Jack.

The longitude is between [-180, 180] (negative for West) and the latitude is between [-85, 85] (negative for South)

Output

Output the tag for the tile in the specified level that contains the location in a single line.

You can assume that the location will not be at the boundary of any tiles.

Sample Input

80 33 2
-80 -33 4
72.12 46.68 10

Sample Output

trt
ttrqt
trtrstqsrqs

Notes

You can use the 'log(double)' function to calculate the natural logarithm, and 'tan(double)' to calculate the tangent value. Both of these functions are included in the header '<math.h>' for C or '<cmath>' for C++.


Source

Zhejiang Provincial Programming Contest 2007

 此题用的是二分法~ 要理解题意

code:

#include <iostream>
#include <cstring>
#include <cmath>

const double pi=acos(-1);

using namespace std;
int main()
{
	double longit,lati;
	double startx,starty,endx,endy,midx,midy;
	int level;
	while(cin>>longit>>lati>>level)
	{
		string res="t";
		double x,y;
		x=longit*pi/180;
		y=log(tan(pi/4.0 +(lati*pi/180.0)/2.0));
		
		startx=-180.0*pi/180;
		endx=180.0*pi/180;
		starty=log(tan(pi/4.0 +(-85.0*pi/180.0)/2.0));
		endy=log(tan(pi/4.0 +(85.0*pi/180.0)/2.0));
		for(int i=0;i<level;i++)
		{
			midx=(startx+endx)/2.0;
			midy=(starty+endy)/2.0;
		
			if(x>midx && y>midy)
			{
				res+="r";
				startx=midx;
				starty=midy;
			}
			else if(x>midx && y<midy)
			{
				res+="s";
				
				startx=midx;
				endy=midy;
			}
			else if(x<midx && y>midy)
			{
				res+="q";
				
				endx=midx;
				starty=midy;
			}
			else if(x<midx && y<midy)
			{
				res+="t";
				
				endx=midx;
				endy=midy;
			}
			
		}
		cout<<res<<endl;
		
		
	}
	
	
	return 0;
}


Image Transformation

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 8   Accepted Submission(s) : 10
Problem Description

The image stored on a computer can be represented as a matrix of pixels. In the RGB (Red-Green-Blue) color system, a pixel can be described as a triplex integer numbers. That is, the color of a pixel is in the format "r g b" where r, g and b are integers ranging from 0 to 255(inclusive) which represent the Red, Green and Blue level of that pixel.

Sometimes however, we may need a gray picture instead of a colorful one. One of the simplest way to transform a RGB picture into gray: for each pixel, we set the Red, Green and Blue level to a same value which is usually the average of the Red, Green and Blue level of that pixel (that is (r + g + b)/3, here we assume that the sum of r, g and b is always dividable by 3).

You decide to write a program to test the effectiveness of this method.

Input

The input contains multiple test cases!

Each test case begins with two integer numbers N and M (1 <= N, M <= 100) meaning the height and width of the picture, then three N * M matrices follow; respectively represent the Red, Green and Blue level of each pixel.

A line with N = 0 and M = 0 signals the end of the input, which should not be proceed.

Output

For each test case, output "Case #:" first. "#" is the number of the case, which starts from 1. Then output a matrix of N * M integers which describe the gray levels of the pixels in the resultant grayed picture. There should be N lines with M integers separated by a comma.

Sample Input

2 2
1 4
6 9
2 5
7 10
3 6
8 11
2 3
0 1 2
3 4 2
0 1 2
3 4 3
0 1 2
3 4 4
0 0

Sample Output

Case 1:
2,5
7,10
Case 2:
0,1,2
3,4,3


 

Source

Zhejiang Provincial Programming Contest 2007
 
code:
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int r[10009];
	int g[10009];
	int b[10009];
int main()
{
	
     int m,n;
     int t=0;
     while(cin>>n>>m)
     {
     	if(n==0&&m==0) break;
     	
memset(r,0,sizeof(r));
     	memset(g,0,sizeof(g));
     	memset(b,0,sizeof(b));
     	for(int i=0;i<n*m;i++)
     	{
	     	cin>>r[i];
	     	
	     }
	     for(int i=0;i<n*m;i++)
	     {
     		cin>>g[i];
     	}
     	for(int i=0;i<n*m;i++)
     	{
	     	cin>>b[i];
	     }
	     cout<<"Case "<<++t<<":"<<endl;
	     for(int j=0;j<n*m;j++)
	     {
     		cout<<(r[j]+g[j]+b[j])/3;
     		if((j+1)%m==0)cout<<endl;
     		else 
     		cout<<",";
     	}
     }
	return 0;
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值