贪心水题。UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing
2015-09-15 08:01
561 查看
UVA 11636 Hello World
二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度。
LA 3602 DNA Consensus String
贪心构造,每一位上选出现次数最多的。
UVA 10970 Big Chocolate (等效转换)
题目问最少的刀数是迷惑人的,从块数来看,每次切只会增加一块巧克力。
UVA 10340 All in All
贪心选,两个指针,t中的当前元素能选就选,不选这个元素对答案就没有贡献了,一定不会更优。
UVA 11039 Building Designing
贪心,按照绝对值排序,记录一下上次的符号,能选就选。
二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度。
#include<cstdio> int main() { int n,kas = 0; while(scanf("%d",&n),n>0){ int r = 0; for(n--;n;n>>=1) r++; printf("Case %d: %d\n",++kas,r); } return 0; }
LA 3602 DNA Consensus String
贪心构造,每一位上选出现次数最多的。
#include<bits/stdc++.h> using namespace std; const int maxm = 55,maxn = 1e3+1; int id[256]; char rid[] = "ACGT"; int ct[4][maxn]; char s[maxn+5]; int main() { id['A'] = 0; id['C'] = 1; id['G'] = 2; id['T'] = 3; int T;cin>>T; while(T--){ int m,n; scanf("%d%d",&m,&n); for(int i = 0; i < 4; i++) fill(ct[i],ct[i]+n,0); for(int i = 0; i < m; i++){ scanf("%s",s); for(int j = 0; j < n; j++){ ct[id[s[j]]][j]++; } } int sum = 0; for(int j = 0; j < n; j++){ int k = 0; for(int i = 1; i < 4; i++) if(ct[i][j] > ct[k][j]) k = i; putchar(rid[k]); sum += m-ct[k][j]; } printf("\n%d\n",sum); } return 0; }
UVA 10970 Big Chocolate (等效转换)
题目问最少的刀数是迷惑人的,从块数来看,每次切只会增加一块巧克力。
#include<bits/stdc++.h> using namespace std; int main() { int m,n; while(~scanf("%d%d",&m,&n)){ printf("%d\n",m*n-1); } return 0; }
UVA 10340 All in All
贪心选,两个指针,t中的当前元素能选就选,不选这个元素对答案就没有贡献了,一定不会更优。
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5; char s[maxn],t[maxn]; int main() { while(~scanf("%s%s",s,t)){ char *p = s,*q = t; while(*p){ while(*q && *q != *p) q++; if(!*q) break; p++; q++; } if(!*p) puts("Yes"); else puts("No"); } return 0; }
UVA 11039 Building Designing
贪心,按照绝对值排序,记录一下上次的符号,能选就选。
#include<bits/stdc++.h> using namespace std; const int maxn = 5e5+5; int a[maxn]; bool cmp(int a,int b) { return abs(a) < abs(b); } int main() { int T; cin>>T; while(T--){ int n; scanf("%d",&n); for(int i = 0; i < n; i++) scanf("%d",a+i); sort(a,a+n,cmp); int ans = 1; bool fg = a[0]>0; for(int i = 1; i < n; i++){ bool tfg = a[i]>0; if( (tfg&&!fg) || (!tfg&&fg) ) { fg = tfg; ans++; } } printf("%d\n",ans); } return 0; }
相关文章推荐
- Repeated DNA Sequences 解答
- The requested URL Not Found问题
- The requested URL Not Found问题
- UIScrollView 实践经验(转)
- [Android UI开发] Android 性能调优点
- [Android UI开发] Android中处理崩溃异常
- uestc 449(扫描线)
- UIView 子界面的处理
- iOS UIImage UIImageView 展示图片 不变形 处理
- java常用集合类:Deque,ArrayList,HashMap,HashSet
- ArrayAdapter requires the resource ID to be a TextView问题
- 【LeetCode 232: Implement Queue using Stacks】
- Android 5.1 SystemUI 之 Status Bar 加载流程
- uva 11995 I Can Guess the Data Structure!
- ZOJ 2747 Windows Message Queue
- 约束,在ios8 没问题,在ios7崩溃的问题,UItextField
- 利用UIScrollView实现几个页面的切换
- UICollectionView简介
- Android Bluetooth4.0(BLE是Bluetooth Low Energy的简称) 官方API
- 限制UITextView中的字数