codeforce R 491 (div2)
本来打完就想写的,,奈何舍友要睡了,我开个台灯感觉怪怪的,就没写。
A题竟然一开始wa了。。。后来发现对于c和a还有c和b的关系没有判断,,丢掉了很多罚时。
B题我的方法是 计算 sum,然后 分别统计 2、3、4的个数,一个一个试,具体看代码(前面快速io有点长见谅
package R491; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main2 { static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer tok; static boolean hasNext() { while(tok==null||!tok.hasMoreTokens()) try{ tok=new StringTokenizer(in.readLine()); } catch(Exception e){ return false; } return true; } static String next() { hasNext(); return tok.nextToken(); } static long nextLong() { return Long.parseLong(next()); } static int nextInt() { return Integer.parseInt(next()); } static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) { int n = nextInt(); int a[] = new int[n]; int b[] = new int[8]; int sum = 0; for(int i=0;i<n;i++){ a[i] = nextInt(); b[a[i]]++; sum+=a[i]; } int num = 0; while (sum<4.5*n){ if (b[2]>0){ sum+=3; b[2]--; num++; }else if (b[3]>0){ sum+=2; b[3]--; num++; }else if (b[4]>0){ sum+=1; b[4]--; num++; } } out.print(num); out.flush(); } }
C 一开始还以为可能有点意思,然后二分板子就出来了,没啥可说的,中间竟然wa了一发,,很玄学, ,判断时 如果 把 num1>=num2 写成 num1>=(double)n/2 就会wa。。。
package R491; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main3 { static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer tok; static boolean hasNext() { while(tok==null||!tok.hasMoreTokens()) try{ tok=new StringTokenizer(in.readLine()); } catch(Exception e){ return false; } return true; } static String next() { hasNext(); return tok.nextToken(); } static long nextLong() { return Long.parseLong(next()); } static int nextInt() { return Integer.parseInt(next()); } static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); static long n; public static void main(String[] args) { n = nextLong(); long l = 1; long r = n; while (l<=r){ long mid=(l+r)/2; if (caneat(mid)){ r=mid-1; }else { l=mid+1; } } out.print(l); out.flush(); } public static boolean caneat(long k){ long num=0; long num2 = 0; long temp = n; while (temp>0){ if (temp<k){ num+=temp; break; } num+=k; temp-=k; num2+=(temp/10); temp-=temp/10; } if (num>=num2){ return true; }else { return false; } } }
D题就很和蔼可亲了,竟然只有两行,直接暴力,我的方法是 umm懒得说看代码吧
package R491; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main4 { static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer tok; static boolean hasNext() { while(tok==null||!tok.hasMoreTokens()) try{ tok=new StringTokenizer(in.readLine()); } catch(Exception e){ return false; } return true; } static String next() { hasNext(); return tok.nextToken(); } static long nextLong() { return Long.parseLong(next()); } static int nextInt() { return Integer.parseInt(next()); } static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) { String s[] = new String[2]; for(int i=0;i<2;i++){ s[i] = next(); } if (s[0].length()==1){ out.print(0); out.flush(); return; } char ch1[] = s[0].toCharArray(); char ch2[] = s[1].toCharArray(); int ans = 0; for(int i=0;i<ch1.length;i++){ if (ch1[i]=='0'&&ch2[i]=='0'){ if (i==0){ if (ch1[i+1]=='0'){ ans++; ch1[i+1]='X'; ch1[i]=ch2[i]='X'; }else if (ch2[i+1]=='0'){ ans++; ch2[i+1]='X'; ch1[i]=ch2[i]='X'; } }else if (i<ch1.length-1){ if (ch1[i-1]=='0'){ ans++; ch1[i-1]='X'; ch1[i]=ch2[i]='X'; }else if (ch2[i-1]=='0'){ ans++; ch2[i-1]='X'; ch1[i]=ch2[i]='X'; }else if (ch1[i+1]=='0'){ ans++; ch1[i+1]='X'; ch1[i]=ch2[i]='X'; }else if (ch2[i+1]=='0'){ ans++; ch2[i+1]='X'; ch1[i]=ch2[i]='X'; } }else if (i== ch1.length-1) { if (ch1[i - 1] == '0') { ans++; ch1[i - 1] = 'X'; ch1[i] = ch2[i] = 'X'; } else if (ch2[i - 1] == '0') { ans++; ch2[i - 1] = 'X'; ch1[i] = ch2[i] = 'X'; } } } } out.print(ans); out.flush(); } }
E 啊哈哈哈哈,尴尬而不失礼貌的微笑,因为我太弱了又很垃圾还是一个数学白痴所以我没写出来。。。
F学长都没写。。。学长51分钟过掉ABCDE好像就开始挂机了,发现F有点难就睡觉去了,然后D题掉了,囍。
近期:补一下排列组合,抓紧学个tarjan把前天的E题补掉。(对不起是我太弱了不会tarjan
rating:1548
忽然发现今晚还有一场,我可能要1600+了欸嘿嘿嘿。