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的更多相关文章

  1. LA 3602 DNA Consensus String

    最近审题老是一错再错,Orz 题目中说求一个Hamming值总和最小的字符串,而不是从所给字符中找一个最小的 这样的话,我们逐列处理,所求字符串当前位置的字符应该是该列中出现次数最多其次ASCII值最 ...

  2. LA 3602 DNA Consensus String (暴力枚举)

    题意:给定m个长度为n的DNA序列,求一个最短的DNA序列,使得总Hamming距离最小. Hamming距离等于字符不同的位置个数. 析:看到这个题,我的第一感觉是算时间复杂度,好小,没事,完全可以 ...

  3. LA 3602 - DNA Consensus String 枚举

    原题地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  4. UVa 3602 - DNA Consensus String 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  5. PAT甲题题解-1125. Chain the Ropes (25)-贪心水题

    贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...

  6. UVA 11389 The Bus Driver Problem 贪心水题

    题目链接:UVA - 11389 题意描述:有n个司机,n个早班路线和n个晚班路线,给每个司机安排一个早班路线和一个晚班路线,使得每个早班路线和晚班路线只属于一个司机.如果一个司机早班和晚班总的驾驶时 ...

  7. UVa(11292),贪心水题

    蓝书P1, 很简单的一个贪心选择,用能力小的去砍小的.本来想双重循环,哎,傻逼了,直接遍历选手,碰到能砍的就砍掉. #include <stdio.h> #include <algo ...

  8. 【贪心算法】POJ-2393 简单贪心水题

    一.题目 Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over ...

  9. cogs 1440. [NOIP2013]积木大赛 贪心水题

    1440. [NOIP2013]积木大赛 ★★   输入文件:BlockNOIP2013.in   输出文件:BlockNOIP2013.out   简单对比时间限制:1 s   内存限制:128 M ...

随机推荐

  1. layer常用方法

    弹出层layer的使用 弹出层layer的使用 Intro layer是一款web弹层组件,致力于服务各个水平段的开发人员.layer官网:http://layer.layui.com/ layer侧 ...

  2. HDU - 5451 Best Solver(循环节+矩阵快速幂)

    Best Solver The so-called best problem solver can easily solve this problem, with his/her childhood ...

  3. GridView_RowDataBound 常用方法

    1.这个就不用说,鼠标经过行颜色变化 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    { ...

  4. JS中map list 数组的迭代

    后台传给前台一个map 前台如何迭代呢 $.post("getSys.jhtml", function(data){ var temp = ""; $.each ...

  5. codevs2924 数独挑战

    2924 数独挑战 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description "芬兰数学家因卡拉,花费3个月时间设计出了世界 ...

  6. [原创]内网SSH密码爆破工具sshcrack(配合Cscan批量弱口令检测)

    0x000 前言 sshcrack是一个命令行下的SSH密码爆破工具,适用于内渗中SSH密码检测 当然也可用于外网SSH密码爆破,支持Windows/Linux,其它系统未测.Tip1 0x001 目 ...

  7. 两数相加LeetCode

    给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和 ...

  8. IntelliJ IDEA 打包Maven 构建的 Java 项目

    方法 2,一键生成方便到哭 打开maven项目路径     一键生成     3.生成jar 目标文件在 path/target/xx.jar下面 方法 1 选中Java项目工程名称,在菜单中选择 F ...

  9. I.Algorithm Choosing Mushrooms

    链接:https://ac.nowcoder.com/acm/contest/908/I 题意: Baby bear and his good friends are very fond of mus ...

  10. csdn自动展开+去广告+净化剪切板+免登陆(如有侵权,立即删博)

    对于csdn的广告大家想必......又没钱充VIP,怎么办,下面是脚本源码: 重要的事说三遍:如有侵权,立即删除!如有侵权,立即删除!如有侵权,立即删除! // ==UserScript== // ...