Codeforces Round #218 (Div. 2)
500pt,
题目链接:http://codeforces.com/problemset/problem/371/A
分析:k-periodic说明每一段长度为k,整个数组被分成这样长度为k的片段,要使得修改最少,求出k长度的片段中每个位置出现次数最多的数就行。
代码:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
using namespace std;
int n,k;
int input[110];
map<int,int> m[110];
int right1[110];
int findMax(map<int,int> m)
{
int index = 0;
int cnt = 0;
map<int,int>::iterator it = m.begin();
for(;it!=m.end();it++)
{
if(it->second>cnt)
{
cnt = it->second;
index = it->first;
}
}
return index;
}
int main()
{
while(cin>>n>>k)
{
memset(input,0,sizeof(input));
memset(right1,0,sizeof(right1));
for(int i=0;i<k;i++)
m[i].clear();
for(int i=0;i<n;i++)
cin>>input[i];
for(int i=0;i<n;i++)
{
m[i%k][input[i]]++;
}
for(int i=0;i<k;i++)
{
right1[i] = findMax(m[i]);
}
int ret = 0;
for(int i=0;i<n/k;i++)
{
for(int j=0;j<k;j++)
{
if(input[i*k+j]!=right1[j])
ret++;
}
}
cout<<ret<<endl; }
return 0;
}
1000pt: 题目链接:
http://codeforces.com/problemset/problem/371/B
题目分析:将每个数都除以2,3,5直到不能再除,如果最后数不一样就返回-1,一样就根据除的次数返回,具体看代码,这题我也是看了别人代码明白过来的
代码:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
using namespace std;
int a,b;
int ret;
void div(int p)
{
int cnta = 0;
int cntb = 0;
while(a%p==0&&a>0)
{
cnta++;
a/=p;
}
while(b%p==0&&b>0)
{
cntb++;
b/=p;
}
ret += abs(cnta-cntb);
}
int main()
{
while(cin>>a>>b)
{
ret=0;
div(2);
div(3);
div(5);
cout<<(a==b?ret:-1)<<endl;
} return 0;
}
1500:题目链接:
http://codeforces.com/problemset/problem/371/C
分析:不要直接模拟计算会超时,直接二分查找,0-1e14,看哪个最能满足条件
代码:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
using namespace std;
string s;
int nb1,ns1,nc1;//做一份需要的数量
int nb,ns,nc;//目前有的数量
int pb,ps,pc;__int64 r;//价格
bool ok(__int64 m)
{
__int64 bneed = (m*nb1<=nb)?0:(m*nb1-nb)*pb;
__int64 sneed = (m*ns1<=ns)?0:(m*ns1-ns)*ps;
__int64 cneed = (m*nc1<=nc)?0:(m*nc1-nc)*pc;
__int64 need = bneed+sneed+cneed;
if(r>=need)
return true;
else
return false;
}
int main()
{
while(cin>>s)
{
nb1=0;ns1=0;nc1=0;
for(int i=0;i<s.length();i++)
{
if(s[i]=='B')
nb1++;
if(s[i]=='S')
ns1++;
if(s[i]=='C')
nc1++;
}
cin>>nb>>ns>>nc;
cin>>pb>>ps>>pc>>r;
__int64 ll=0,rr=1e14;
while(ll<=rr-1)
{
__int64 mid = (ll+rr+1)/2;
if(ok(mid))
{
ll = mid;
}
else
{
rr = mid-1;
}
}
cout<<ll<<endl; }
return 0;
}
Codeforces Round #218 (Div. 2)的更多相关文章
- 二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers
题目传送门 /* 题意:一个汉堡制作由字符串得出,自己有一些原材料,还有钱可以去商店购买原材料,问最多能做几个汉堡 二分:二分汉堡个数,判断此时所花费的钱是否在规定以内 */ #include < ...
- Codeforces Round #218 (Div. 2) D. Vessels
D. Vessels time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #218 (Div. 2) C. Hamburgers
C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #218 (Div. 2) B. Fox Dividing Cheese
B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #218 (Div. 2) C题
C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #218 (Div. 2) (线段树区间处理)
A,B大水题,不过B题逗比了题意没理解清楚,讲的太不清楚了感觉= =还是英语弱,白白错了两发. C: 二分答案判断是否可行,也逗比了下...二分的上界开太大导致爆long long了... D: ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- Android进程内存上限
Android应用程序都是在自己单独的进程中运行.Android为不同类型的进程分配了不同的内存使用上限,如果应用进程使用的内存超过了这个上限,则会抛出Out Of Memory异常,接着进程也被ki ...
- Oracle 11g RAC OCR 与 db_unique_name 配置关系 说明
一. 问题一 在做RAC standby 的alert log里发现如下错误: SUCCESS: diskgroup DATA was mounted ERROR: failed toestablis ...
- 在eclipse上安装 sdk出现的各种问题
在eclipse上下进行android开发需要 有android SDK 和ADT 一般adt版本瑶台低, 会被提示安装较高版本的ADT, 不然, SDK可能无法使用 在安装 SDK过程中出现这样 ...
- java--内部类访问final成员
局部类只能访问外包方法中的final成员.位于方法内部的局部类,可以访问局部类之外,外包方法之内的所以变量和方法,但是生命周期不同,延长生命周期的办法就是将变量设置为final类型. 1)从程序设计语 ...
- VC6.0 导入资源崩溃
等我以后挣钱了一定买正版! 最近学习Win32编程,为了锻炼自己,在网上下载了一个VC6.0作为开发工具,应该是兼容性的问题吧,VC6 经常闹毛病. 今天导入资源的时候VC6出现崩溃的现象. 马上寻求 ...
- jsp页面格式化数字或时间
Tags fmt:requestEncoding fmt:setLocale fmt:timeZone fmt:setTimeZone fmt:bundle fmt:setBundle fmt:m ...
- Jquery学习笔记:通过层次关系获取jquery对象
前面一篇文章,我们介绍了如何通过web标签的id , css样式值来获取jquery对象. 但这只是基本方法,不能满足所有场景的需求. 本文介绍通过dom元素之间的层次关系获取元素.具体是将各种标识符 ...
- linux: /usr/bin/ld: cannot find -lloc
/usr/bin/ld: cannot find -lloc ld链接库的时候没发现loc这个库-lloc本事不是文件名字,要去找这个库就搜索libloc, loc, 不能搜索lloc. /usr1/ ...
- 前端面试题整理(css)
1.介绍所知道的CSS hack技巧(如:_, *, +, \9, !important 之类). CSS hack的原理: 由于不同的浏览器和浏览器各版本对CSS的支持及解析结果不一样,以及CSS优 ...
- mysql死锁问题分析(转)
线上某服务时不时报出如下异常(大约一天二十多次):“Deadlock found when trying to get lock;”. Oh, My God! 是死锁问题.尽管报错不多,对性能目前看来 ...