首页 > 专题系列 > Java解POJ > POJ 1663 Number Steps [解题报告] Java
2013
11-10

POJ 1663 Number Steps [解题报告] Java

Number Steps

问题描述 :

Starting from point (0,0) on a plane, we have written all non-negative integers 0,1,2, … as shown in the figure. For example, 1, 2, and 3 has been written at points (1,1), (2,0), and (3, 1) respectively and this pattern has continued.



You are to write a program that reads the coordinates of a point (x, y), and writes the number (if any) that has been written at that point. (x, y) coordinates in the input are in the range 0…5000.

输入:

The first line of the input is N, the number of test cases for this problem. In each of the N following lines, there is x, and y representing the coordinates (x, y) of a point.

输出:

For each point in the input, write the number written at that point or write No Number if there is none.

样例输入:

3
4 2
6 6
3 4

样例输出:

6
12
No Number

解题代码:

//* @author  [email protected]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
		int n=new Integer(stdin.readLine());	
		StringTokenizer tokens;
		int x,y;
		for(int i=0;i< n;i++){
			tokens=new StringTokenizer(stdin.readLine());
			x=new Integer(tokens.nextToken());		
			y=new Integer(tokens.nextToken());
			if(x==y||(x-2)==y)System.out.println(x+y-x%2);
			else System.out.println("No Number");
		}
	}
}

  1. 第一句可以忽略不计了吧。从第二句开始分析,说明这个花色下的所有牌都会在其它里面出现,那么还剩下♠️和♦️。第三句,可以排除2和7,因为在两种花色里有。现在是第四句,因为♠️还剩下多个,只有是♦️B才能知道答案。

  2. 其实国内大部分公司对算法都不够重视。特别是中小型公司老板根本都不懂技术,也不懂什么是算法,从而也不要求程序员懂什么算法,做程序从来不考虑性能问题,只要页面能显示出来就是好程序,这是国内的现状,很无奈。