Bestcoder #49
来源:互联网 发布:javascript generator 编辑:程序博客网 时间:2024/04/29 23:15
1001 Untitled
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
/** * 2015年8月1日 下午7:15:14 * PrjName:Bc49-01 * @ Semprathlon */import java.io.*;import java.util.*;public class Main { static ArrayList<Integer> v=new ArrayList<Integer>(); static int[] a,f; static int lowbit(int x){ return x&(-x); } static int get(int x){ int res=0; while(x>0){ res++; x-=lowbit(x); } return res; } public static void main(String[] args) throws IOException{ // TODO Auto-generated method stub InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); int T=in.nextInt(); while(T-->0){ v.clear(); int n=in.nextInt(); int m=in.nextInt(); for(int i=1;i<=n;i++) v.add(in.nextInt()); Collections.sort(v); f=new int[1<<n]; Arrays.fill(f, -1); f[0]=m; //out.println(n); int ans=Integer.MAX_VALUE; for(int i=0;i<(1<<n);i++) if (f[i]>0) for(int j=0;j<n;j++) if (((1<<j)&i)==0){ int k=i|(1<<j); f[k]=f[i]%v.get(j); if (f[k]==0) ans=Math.min(ans, get(k)); } if (ans==Integer.MAX_VALUE) out.println(-1); else out.println(ans); } out.flush(); out.close(); }}
1002 Three Palindromes
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description
Can we divided a given string S into three nonempty palindromes?Input
First line contains a single integerlatexT≤20 which denotes the number of test cases.
For each test case , there is an single line contains a string S which only consist of lowercase English letters.latex1≤|s|≤20000 Output
For each case, output the “Yes” or “No” in a single line.Sample Input
2
abc
abaadadaSample Output
Yes
No
赛时的Hash做法:
/** * 2015年8月1日 下午7:47:15 * PrjName:Bc49-02 * @ Semprathlon */import java.io.*;import java.util.*;public class Main { static long pri=29L; static long lh(String s,long res,int p){ return res*pri+(long)(s.charAt(p)-'a'); } static long rh(String s,long res,int p,long m){ return res+(long)(s.charAt(p)-'a')*m; } static BitSet v=new BitSet(20010); public static void main(String[] args) throws IOException{ // TODO Auto-generated method stub InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); int T=in.nextInt(); while(T-->0){ String s=new String(in.next()); int len=s.length(); //s=s+"#"+(new StringBuffer(s).reverse().toString()); //out.println(s); boolean ans=false; long l1=0L,r1=0L,tmp=1L; for(int i=0;i<len;i++){ if (ans) break; l1=lh(s, l1, i); r1=rh(s, r1, i, tmp); //out.println(i+" "+l1+" "+r1); tmp*=pri; //if ((i&1)>0) continue; if (l1==r1){ //out.println("f"+i); long l2=0L,r2=0L,tmp2=1L; v.clear(); for(int j=i+1;j<len;j++){ l2=lh(s,l2,j); r2=rh(s,r2,j,tmp2); tmp2*=pri; //if (((j-i+1)&1)>0) continue; if (l2==r2) v.set(j); } l2=0L;r2=0L;tmp2=1L; for(int j=len-1;j>i;j--){ l2=lh(s,l2,j); r2=rh(s,r2,j,tmp2); tmp2*=pri; //if (((len-j+1)&1)>0) continue; if (l2==r2&&v.get(j-1)){ ans=true;break; } } } } out.println(ans?"Yes":"No"); } out.flush(); out.close(); }}
首次尝试去hack别人不成,还被人黑了,立马TLE
题解介绍的多种方法中,个人认为二分+hash代码量较少,如何实现?
- Bestcoder #49
- BestCoder Round #49 ($) 1001
- BestCoder Round #49 ($)
- BestCoder
- bestcoder
- BestCoder #49 Untitled HDU 5339
- BestCoder Round #49 ($) 1001 Untitled
- Bestcoder Round#49 1001Untitled
- BestCoder Round #49 HDU5339 Untitled
- hdu5339-Untitled // BestCoder Round #49 ($) 1001 (搜索)
- BestCoder Round #49 Untitled / hdu5339 (搜索)
- hdu5339&bestcoder(#49)a题
- hdu5340&Bestcoder(#49)b题
- BestCoder Round #49 Dynamic Cactus 即 hdu5342
- BestCoder Round #49 ($) HDOJ5339 Untitled(dfs)
- BestCoder Round #49 ($) HDOJ5340 Three Palindromes(暴力)
- BestCoder Round #49 ($) HDU 5339 Untitled(1001)
- HDU 5339 Untitled ——BestCoder Round #49
- 支持向量机的理解
- Thread中start()和run()的区别
- WINDOWS 7 配置驱动开发环境(wdk7.60)
- Java Collection详解,Java中的集合框架Collection上
- 黑马程序员—学习笔记3—经典的丢手绢程序
- Bestcoder #49
- [Android源码解析] 清空应用内部文件缓存
- 附上windebug常用调试命令
- Nginx基本数据结构之ngx_http_request_t结构体
- Part3. OSGi之模块-Bundle
- windebug查看KeServiceDescriptorTable
- BestCoder #50
- linux内核中的IS_ERR()、PTR_ERR()、ERR_PTR()
- 【LeetCode】2(7)Remove Element(Easy)