| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:感谢啊~~你这个数据让我知道1点也不能删In Reply To:感谢啊~~你这个数据让我知道1点也不能删 Posted by:shinejose at 2011-05-14 11:50:42
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static int count = 0;
public static int getheight(ArrayList a) {
int height = 0;
ArrayList str1 = new ArrayList();
ArrayList str2 = new ArrayList();
int max = 0;
int min = 0;
for(int i=0; i<a.size(); i++) {
String str = a.get(i).toString();
String[] strgroup = str.split(" ");
str2.add(strgroup[1]);
String s = str2.get(i).toString();
int c = Integer.parseInt(s);
if(c - max > 0) {
max = c;
}
}
for(int i=0; i<a.size(); i++) {
String s = str2.get(i).toString();
int c = Integer.parseInt(s);
if(c - min < 0) {
min = c;
}
}
height = max - min;
return height;
}
public static int getwidth(ArrayList b) {
int width = 0;
ArrayList str1 = new ArrayList();
ArrayList str2 = new ArrayList();
int max = 0;
int min = 0;
for(int i=0; i<b.size(); i++) {
String str = b.get(i).toString();
String[] strgroup = str.split(" ");
str2.add(strgroup[0]);
String s = str2.get(i).toString();
int c = Integer.parseInt(s);
if(c - max > 0) {
max = c;
}
}
for(int i=0; i<b.size(); i++) {
String s = str2.get(i).toString();
int c = Integer.parseInt(s);
if(c - min < 0) {
min = c;
}
}
width = max - min;
return width;
}
public static void mysubtraction(Object object, Object object2, ArrayList<Integer> a, ArrayList<Integer> b) {
String str1 = object.toString();
String str2 = object2.toString();
if(str1.charAt(0) - str2.charAt(0) == 0) {
b.add( Math.abs( str1.charAt(2) - str2.charAt(2) ) );
}else if(str1.charAt(2) - str2.charAt(2) == 0) {
a.add( Math.abs( str1.charAt(0) - str2.charAt(0) ) );
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
while(Integer.parseInt(str) != 0) {
String strr = sc.nextLine();
ArrayList num = new ArrayList();
if(str.length() == 1) {
count ++ ;
}
while(strr.split(" ").length != 1) {
num.add(strr);
strr = sc.nextLine();
}
ArrayList<Integer> leftright = new ArrayList<Integer>();
ArrayList<Integer> updown = new ArrayList<Integer>();
for(int k=0; k<num.size(); k++) {
if(k < num.size() - 1) {
mysubtraction(num.get(k + 1), num.get(k), leftright, updown);
}else {
mysubtraction(num.get(num.size() - 1), num.get(0), leftright, updown);
}
}
int leftrightsum = 0;
int updownsum = 0;
for(int k=0; k<leftright.size(); k++) {
leftrightsum = leftrightsum + leftright.get(k);
}
for(int k=0; k<updown.size(); k++) {
updownsum = updownsum + updown.get(k);
}
int width = getwidth(num);
int height = getheight(num);
if(leftrightsum == 2 * width && updownsum == 2 * height) {
System.out.println("Floor #" + count);
System.out.println("Surveillance is possible.");
}else {
System.out.println("Floor #" + count);
System.out.println("Surveillance is impossible.");
}
str = strr;
}
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator