2016年9月22日 星期四

Q11875 - Brick Game

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2986
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn=new Scanner(System.in);
int n=Integer.parseInt(scn.nextLine());
for(int i=1;i<=n;i++){
String str[]=scn.nextLine().split(" ");
int num=str.length/2;
System.out.printf("Case %d: %s\n",i,str[num]);
}
}
/*
題目:Q11875 - Brick Game
作者:1010
時間:西元 2016 年 9 月 */
}

這題就取中位數就好了

Q11494: Queen

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2489

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn=new Scanner(System.in);
while(scn.hasNext()){
int x1=scn.nextInt(),y1=scn.nextInt(),x2=scn.nextInt(),y2=scn.nextInt(),a=Math.abs(x1-x2),b=Math.abs(y1-y2);
if(x1==0&&y1==0&&x2==0&&y2==0)
break;
else if(x1==x2&&y1==y2)
System.out.println("0");
else if(a==b||a==0||b==0)
System.out.println("1");
else
System.out.println("2");
}
}
/*
題目:Q11494: Queen
作者:1010
時間:西元 2016 年 9 月 */
}
當x1=x2以及y1=y2時代表相同的點輸出0不需移動
當x2-x1=y2-y1 絕對值一樣時或x2-x1=0或y2-y1=0時輸出1
其餘輸出2