贪心水题。UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing
UVA 11636 Hello World
二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度。
#include<cstdio> int main()
{
int n,kas = ;
while(scanf("%d",&n),n>){
int r = ;
for(n--;n;n>>=) r++;
printf("Case %d: %d\n",++kas,r);
}
return ;
}
LA 3602 DNA Consensus String
贪心构造,每一位上选出现次数最多的。
#include<bits/stdc++.h>
using namespace std;
const int maxm = ,maxn = 1e3+; int id[];
char rid[] = "ACGT";
int ct[][maxn];
char s[maxn+];
int main()
{
id['A'] = ; id['C'] = ; id['G'] = ; id['T'] = ;
int T;cin>>T;
while(T--){
int m,n; scanf("%d%d",&m,&n);
for(int i = ; i < ; i++) fill(ct[i],ct[i]+n,);
for(int i = ; i < m; i++){
scanf("%s",s);
for(int j = ; j < n; j++){
ct[id[s[j]]][j]++;
}
}
int sum = ;
for(int j = ; j < n; j++){
int k = ;
for(int i = ; i < ; i++) if(ct[i][j] > ct[k][j]) k = i;
putchar(rid[k]); sum += m-ct[k][j];
}
printf("\n%d\n",sum);
}
return ;
}
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-);
}
return ;
}
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 ;
}
UVA 11039 Building Designing
贪心,按照绝对值排序,记录一下上次的符号,能选就选。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+;
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 = ; i < n; i++) scanf("%d",a+i);
sort(a,a+n,cmp);
int ans = ; bool fg = a[]>;
for(int i = ; i < n; i++){
bool tfg = a[i]>;
if( (tfg&&!fg) || (!tfg&&fg) ) {
fg = tfg; ans++;
}
}
printf("%d\n",ans);
}
return ;
}
贪心水题。UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing的更多相关文章
- LA 3602 DNA Consensus String
最近审题老是一错再错,Orz 题目中说求一个Hamming值总和最小的字符串,而不是从所给字符中找一个最小的 这样的话,我们逐列处理,所求字符串当前位置的字符应该是该列中出现次数最多其次ASCII值最 ...
- LA 3602 DNA Consensus String (暴力枚举)
题意:给定m个长度为n的DNA序列,求一个最短的DNA序列,使得总Hamming距离最小. Hamming距离等于字符不同的位置个数. 析:看到这个题,我的第一感觉是算时间复杂度,好小,没事,完全可以 ...
- LA 3602 - DNA Consensus String 枚举
原题地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVa 3602 - DNA Consensus String 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- PAT甲题题解-1125. Chain the Ropes (25)-贪心水题
贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...
- UVA 11389 The Bus Driver Problem 贪心水题
题目链接:UVA - 11389 题意描述:有n个司机,n个早班路线和n个晚班路线,给每个司机安排一个早班路线和一个晚班路线,使得每个早班路线和晚班路线只属于一个司机.如果一个司机早班和晚班总的驾驶时 ...
- UVa(11292),贪心水题
蓝书P1, 很简单的一个贪心选择,用能力小的去砍小的.本来想双重循环,哎,傻逼了,直接遍历选手,碰到能砍的就砍掉. #include <stdio.h> #include <algo ...
- 【贪心算法】POJ-2393 简单贪心水题
一.题目 Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over ...
- cogs 1440. [NOIP2013]积木大赛 贪心水题
1440. [NOIP2013]积木大赛 ★★ 输入文件:BlockNOIP2013.in 输出文件:BlockNOIP2013.out 简单对比时间限制:1 s 内存限制:128 M ...
随机推荐
- 实训随笔4:HTML初入门
1.<td>与<tr>标签 表格制作时,应该一行一行的画,即<tr>应该包含<td>标签,正确示例如下: <h3>测试数组初始化与操作< ...
- SQL 截取时间
-- 获取系统时间 print getdate() -- 获取3天前的时间 print dateadd(day, -3 , getdate()) -- 获取3天后的时间 print dateadd(d ...
- [poj] Catch That Cow--bfs
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- 洛谷P3003 [USACO10DEC]苹果交货Apple Delivery
P3003 [USACO10DEC]苹果交货Apple Delivery 题目描述 Bessie has two crisp red apples to deliver to two of her f ...
- 剑指Offer的学习笔记(C#篇)-- 序列化二叉树
题目描述 请实现两个函数,分别用来序列化和反序列化二叉树 一 . 理解题意 二叉树的序列化,是将一个结构化的东西变成扁平化的字符串,序列化二叉树或者是反序列化二叉树就是二叉树和扩展二叉树遍历序列之间的 ...
- [转] ios数组基本用法和排序
http://blog.csdn.net/daiyelang/article/details/18726947 1.创建数组 // 创建一个空的数组 NSArray *array = [NSArray ...
- JDBC基础原理
一.DCL(了解) -- 1. 创建用户CREATE USER 'zhangsan'@'%' IDENTIFIED BY 'zhangsan';-- 2. 用户授权GRANT ALL ON heima ...
- 搞定C系语言的的swap
http://www.cs.utsa.edu/~wagner/CS2213/swap/swap.html 原地址 Parameters, by value and by reference: Both ...
- Codeforces 27D(二分染色)
要点 将边作为染色,如果交叉则异色 #include <cstdio> #include <algorithm> #include <functional> usi ...
- php:判断 是否开启 SSL,CURL,ZIP,GD2,MYSQL,是否安装MEMCACHED
对于php的开发环境,通常需要去先判断下一些扩展和服务时不时已经可用~ 看过的欢迎拍砖,给意见~~ <?php /** * 判断 是否开启 SSL,CURL,ZIP,GD2,MYSQL,是否安装 ...