贪心水题。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 ...
随机推荐
- 20.Consent Controller Get请求逻辑实现
在这里之前讲的这一块的信息就要登场了 需要通过构造函数把这几个注入进来 县引入这三个命名空间 把这三个注入进来,这就是显示依赖 先通过returnUrl拿到这个Request request拿到后,就 ...
- hihocoder1475 数组分拆【DP+前缀和优化】
思路: DP[ i ] 代表以 i 结尾的方案数. dp[i] += sum[i] - sum[j - 1] != 0 ? dp[j] : 0 ; 对于100%的数据,满足1<=N<=10 ...
- MapReduce编程模型
# 文本前期处理 strl_ist = str.replace('\n', '').lower().split(' ') count_dict = {} # 如果字典里有该单词则加 1,否则添加入字典 ...
- iOS风格的弹出框(alert,prompt,confirm)
前两天,自己写了一个简单的插件,在移动端使用,不管是安卓手机还是iOS系统的手机,弹出框统一使用iOS风格的. 该弹出框是依赖于jQuery的,当然也可以将用jq写的几句代码转换为原生代码. 今天把代 ...
- IT兄弟连 Java语法教程 Java开发环境 安装JDK
因为我们要开发Java程序,所以必须在我们的计算机中安装Sun(Oracle)公司提供给我们的JDK.目前最新版本的JDK是JDK 10,但是我们以学习JDK 8为主,所以我们要安装的版本是JDK 8 ...
- Huber鲁棒损失函数
在统计学习角度,Huber损失函数是一种使用鲁棒性回归的损失函数,它相比均方误差来说,它对异常值不敏感.常常被用于分类问题上. 下面先给出Huber函数的定义: 这个函数对于小的a值误差函数是二次的, ...
- python2 学习 数据类型和变量
数据类型和变量 数据类型 整数 Python可以处理任意大小的整数,当然包括负整数,在程序中的表示方法和数学上的写法一模一样,例如:1,100,-8080,0,等等. 计算机由于使用二进制,所以,有时 ...
- Linux用脚本守护进程
while true; do server=`ps -aux | grep tomcat | grep -v grep` if [ ! "$server" ]; then echo ...
- Java thymeleaf模板获取资源文件的内容
我们在某些时候可能需要获取配置文件properties中的配置信息,而不需要用Java传给模板,在模板中就可以直接获取 我们需要在resources/下定义国际化配置文件即可,注意名称必须中messa ...
- 关于office转换成pdf组件服务中的DCOM配置问题
在开始->运行 中录入“dcomcnfg” 单击“确定”后弹出“组件服务”窗口 依次选择“组件服务”->“计算机”->“我的电脑”->“DCOM配置” 在“DCOM配置”下找到 ...