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. Python 数据分析:让你像写 Sql 语句一样,使用 Pandas 做数据分析

    Python 数据分析:让你像写 Sql 语句一样,使用 Pandas 做数据分析 一.加载数据 import pandas as pd import numpy as np url = ('http ...

  2. Thinkphp3.2 下载文件的方法

    今天做一个功能,刚好遇到了一个要下载文件功能的需求,所以把这个基于thinkphp3.2的文件下载功能,描述一下大概的实现方法. 网上有人说用a链接的方法实现,但是这种方法并不安全.所以我们还是用官方 ...

  3. clone分支,修改文件本地commit后, push回原分支失败,处理方法

    从远程clone 一个仓库到本地仓库A后,由于有多个分支,经常需要切换,不同分支区别比较大,切换一下,需要重编译,于是又在本地clone了改动较大的一个分支F到仓库B: 在B仓库改动后,提交到A仓库的 ...

  4. WPF后台修改内容界面不显示问题

    通知3部曲:1.Model继承并实现 INotifyPropertyChanged 接口:2.数据集合使用ObservableCollection<T>集合:3.View使用Binding ...

  5. 解决eclipse js文件报错(转)

    在我们将项目导入Eclipse后,配置好各种编译条件.加载好jar包.配置好tomcat后发现项目还是报错,(前提是项目本身并没有错误,而是我们在初次导入到Eclipse中的时候报错),那是什么原因引 ...

  6. java.lang.NoClassDefFoundError: com/sun/tools/javac/processing/JavacProcessingEnvironment

    最近项目用到了java程序动态编译java源文件,运行程序一直报错,提示错误如下: Can't initialize javac processor due to (most likely) a cl ...

  7. java基础第九篇之final和内部类等

    final关键字:final:最终,终极 final:作用:修饰类,变量,方法.成员变量的访问 1.final修饰变量: final修饰局部变量: 把这个局部变量 变成一个厂里,这个厂里只能被赋值一次 ...

  8. Codeforces Round #561 (Div. 2) C. A Tale of Two Lands

    链接:https://codeforces.com/contest/1166/problem/C 题意: The legend of the foundation of Vectorland talk ...

  9. HDU 1024 A - Max Sum Plus Plus DP + 滚动数组

    http://acm.hdu.edu.cn/showproblem.php?pid=1024 刚开始的时候没看懂题目,以为一定要把那n个数字分成m对,然后求m对中和值最大的那对 但是不是,题目说的只是 ...

  10. springmvc httprequest 使用@Autowired注解

    springmvc httprequest 使用@Autowired注解我一直有个疑问,就是注解后每次的httprequest 是不是都一样的了,然后会不会引发多线程问题? 代码如下: import ...