贪心水题。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 ...
随机推荐
- HDU - 1078 FatMouse and Cheese(记忆化+dfs)
FatMouse and Cheese FatMouse has stored some cheese in a city. The city can be considered as a squar ...
- httpd.conf------Apache主站点配置
Apache主站点配置 Apache的配置由httpd.conf文件配置,因此下面的配置指令都是在httpd.conf文件中修改. Apache主站点基本配置:ServerRoot “/mnt/sof ...
- 杭电1002_A + B Problem II
这是该题的链接http://acm.hdu.edu.cn/showproblem.php?pid=1002 具体的题的内容就不过多描述了,想必你已经知道了,当我看完这道题后就知道咋写了,可是这道题从开 ...
- 51nod1105(二分)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1105 题意:中文题诶- 思路:直接二分答案,再通过二分找有多少 ...
- python-django框架中使用FastDFS分布式文件系统
一.安装FastDFS 1-1:执行docker命令安装 # 安装tracker docker run -dti --network=host --name tracker -v /var/fdfs/ ...
- ios 自定义cell类中获取当前controller push
有时候在自定义cell的过程中,当cell中又button的时候,把button的点击时间写在cell中的时候,需要获取到cell的父视图控制器然后push,可以自建一个类,命名为: GetCurre ...
- C - Distinct Substrings (模板)
https://vjudge.net/problem/SPOJ-DISUBSTR 有两种方式来求去除重读的子串 #include <bits/stdc++.h> using namespa ...
- JQuery入门一
1.为什么要用jquery? 写起来简单,省事,开发效率高,兼容性好 2.什么是jQuery? jQuery是一个兼容多浏览器的JavaScript库 3.如何使用jQuery? 1.导入 <s ...
- 事务&数据库连接池&DBUtils
事务的特性 原子性 指的是 事务中包含的逻辑,不可分割. 一致性 指的是 事务执行前后.数据完整性 隔离性 指的是 事务在执行期间不应该受到其他事务的影响 持久性 指的是 事务执行成功,那么数据应该持 ...
- 实例/静态工厂方法得到bean
<bean id="a" class="com.yundaex.wms.config.TestBeanChild" /> <bean id=& ...