package Karl.Water; /* LANG: JAVA TASK: beads */ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.util.LinkedList; public class beads { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { BufferedReader br = new BufferedReader(new FileReader("beads.in")); PrintWriter pw = new PrintWriter (new FileWriter("beads.out")); int length = Integer.parseInt(br.readLine()); String temp = br.readLine(); LinkedList<Character> necklace = new LinkedList<Character>(); for (int i=0;i<length;i++) { necklace.add(temp.charAt(i)); } int max = 0; for (int i=0;i<length;i++) { char remove = necklace.removeFirst(); char first = necklace.getFirst(); int position = 0; necklace.addLast(remove); int result = 0; boolean allW = false; if (necklace.getFirst()=='w'){ int end1 = find(necklace,0,length,0); result = end1 + 1; if (end1<necklace.size()-1){ int end2 = find (necklace,end1+1,length,0); first = necklace.get(end2); position = end2; result = result + end2 - end1; }else { allW = true; } } else { int end = find(necklace,0,length,0); position = end ; result = result + end + 1; } if (!allW){ if (necklace.getLast()=='w') { int end1 = find(necklace, length-1,position,1); int end2 = find(necklace,end1-1,position,1); if (necklace.get(end2)==first){ result = result ; }else { result = result + length - end1; result = result + end1 - end2 ; } }else { if (necklace.getLast()==first){ result = result; }else { int end = find(necklace,length-1,position,1); result = result + length - end ; } } } if (result >=max){ max = result; } } pw.println(max); pw.close(); br.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static int find(LinkedList<Character> necklace,int startPoint ,int endPoint,int direction){ if (direction ==0 ){ int i=startPoint+1; for (;i<=endPoint-1;i++){ if (necklace.get(i)!=necklace.get(startPoint)&&necklace.get(i)!='w'){ break; } } return i-1; } else { int i=startPoint-1; for (;i>=endPoint+1;i--){ if (necklace.get(i)!=necklace.get(startPoint)&&necklace.get(i)!='w'){ break; } } return i+1; } } }
(2)
package Karl.Water; /* LANG: JAVA TASK: friday */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; public class friday { public static void main(String[] args) throws IOException { int mon=0; int tue=0; int win=0; int thur=0; int fri=0; int sat=0; int sun=0; int j=0; int [][]days = {{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}}; BufferedReader br = new BufferedReader(new FileReader("friday.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("friday.out"))); int N = Integer.parseInt(br.readLine()); int flag; for(int year = 1900;year<=1900+N-1;year++){ flag =(year%4==0 && year%100!=0) || year%400 == 0 ? 1 : 0; for(int k=0;k<12;k++){ for(int i=0;i<days[flag][k];i++,j++){ if(i==12){ if(j%7==0){ mon++; }else if(j%7==1){ tue++; }else if(j%7==2){ win++; }else if(j%7==3){ thur++; }else if(j%7==4){ fri++; }else if(j%7==5){ sat++; }else if(j%7==6){ sun++; } } } } } out.println(sat+" "+sun+" "+mon+" "+tue+" "+win+" "+thur+" "+fri); out.close(); System.exit(0); } }
package Karl.Water; /* LANG: JAVA TASK: gift1 */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.HashMap; import java.util.StringTokenizer; public class gift1 { public static void main(String[] args) throws NumberFormatException, IOException { HashMap<String,Integer> hash = new HashMap<String,Integer>(); StringTokenizer str; BufferedReader br = new BufferedReader(new FileReader("gift1.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("gift1.out"))); int memnum = Integer.parseInt(br.readLine()); String[] s = new String[memnum]; for(int i=0;i<memnum;i++){ s[i] = br.readLine(); hash.put(s[i], 0); } for(int i=0;i<memnum;i++){ String name = br.readLine(); for(int j=0;j<memnum;j++){ if(s[j].equals(name)){ str=new StringTokenizer(br.readLine()); int m = Integer.parseInt(str.nextToken()); int n = Integer.parseInt(str.nextToken()); if(n==0){}else{ hash.put(s[j], hash.get(s[j])-m+m%n);} for(int k=0;k<n;k++){ String na = br.readLine(); hash.put(na,hash.get(na)+ m/n); } } } } for(int i=0;i<memnum;i++){ out.println(s[i]+" "+hash.get(s[i])); } out.close(); System.exit(0); } }
package Karl.Water; /* LANG: JAVA TASK: milk2 */ import java.util.*; import java.io.*; public class milk2 { boolean time[]=new boolean[1000007]; int n,a,b,max_use,max_rex,tmp1,tmp2,start=10000007,stop=0; public static void main(String[] args) throws IOException { new milk2().run(); } void run() throws IOException { Scanner cin=new Scanner(new FileReader("milk2.in")); PrintWriter cout=new PrintWriter(new BufferedWriter(new FileWriter("milk2.out"))); n=cin.nextInt(); for(int i=1;i<=n;i++) { a=cin.nextInt(); b=cin.nextInt(); start=start<a ? start:a; stop=stop>b ? stop:b; for(int j=a;j<b;j++) time[j]=true; } for(int i=start;i<=stop;i++) { if(time[i]) tmp1++; else { max_use=max_use>tmp1 ? max_use:tmp1; tmp1=0; } if(!time[i]) { tmp2++; } else { max_rex=max_rex>tmp2 ? max_rex:tmp2; tmp2=0; } } // System.out.println(max_use+" "+max_rex); cout.println(max_use+" "+max_rex); cout.close(); System.exit(0); } }
这个程序有点问题,到第六七组数据时就出错了,
某君如果知道怎么写留个言也行。
package Karl.Water; /* LANG: JAVA TASK: transform */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class transform { public static void Reflection(char[][] a,int n){ char k; int i,j; for(j=0;j<n;j++){ for(i=0;i<n/2;i++){ k = a[j][i]; a[j][i] = a[j][n-1-i]; a[j][n-1-i] = k; } } } public static void rotate(char a[][],int N) { int layer; for(layer=0; layer<N/2; layer++) { int first = layer; int last = N-1-layer; int i; for(i=layer; i<last; i++) { int offset = i-layer; char top = a[first][i]; a[first][i] = a[last-offset][first]; a[last-offset][first] = a[last][last-offset]; a[last][last-offset] = a[i][last]; a[i][last] = top; } } } public static boolean judge(char[][] a,char[][] b,int n){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(a[i][j]!=b[i][j]){ return false; } } } return true; } public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new FileReader("transform.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("transform.out"))); char[][] a = new char[1000][1000]; char[][] b = new char[1000][1000]; char[][] c = new char[1000][1000]; int n = Integer.parseInt(br.readLine()); String s = new String(); int i,j,k=0; for(i=0;i<n;i++){ s = br.readLine(); for(j=0;j<n;j++){ a[i][j] = s.charAt(j); c[i][j] = s.charAt(j); } } for(i=0;i<n;i++){ s = br.readLine(); for(j=0;j<n;j++){ b[i][j] = s.charAt(j); } } for(int p=0;p<4;p++){ transform.rotate(a, n); if(transform.judge(a, b, n)){ k++; if(p==3) out.println(6); else{ out.println(p+1); break; } } } if(k<1){ transform.Reflection(a, n); if(transform.judge(a, b, n)){ k++; out.println(4); } } if(k!=1&&k!=2){ for(int p=0;p<3;p++){ transform.rotate(a, n); if(transform.judge(a, b, n)){ k++; out.println(5); } } } if(k==0){ out.println(7); } out.close(); System.exit(0); } }