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”三种中任意一种就输 ...
随机推荐
- 基于visual Studio2013解决C语言竞赛题之0418位数操作
题目 解决代码及点评 /************************************************************************/ /* 18. 给 ...
- WTL---WxWidget---MFC 何去何从
C++程序员打交道最多的就是MFC了,这个我不想多说,说来都是泪(C#年年更新,C++十年才出了一个featurePack还不是很好用) 现在另外两支队伍越来越庞大(所谓穷则思变,呵呵),一是WTL, ...
- iOS swift lazy loading
Why bother lazy loading and purging pages, you ask? Well, in this example, it won't matter too much ...
- 蓝牙Profile的概念和常见种类
蓝牙Profile Bluetooth的一个很重要特性,就是所有的Bluetooth产品都无须实现全部 的Bluetooth规范.为了更容易的保持Bluetooth设备之间的兼容,Bluetooth规 ...
- 修改Hadoop作业调度算法过程解析
最近几个星期一直在修改hadoop的计算能力调度算法,遇到了这样那样的问题. 我修改的版本是hadoop-0.20.2 第一步: 将hadoop的源码加载到eclipse中配置使用ant编译 第二步: ...
- 关于怎么C#控制台窗口中怎么创建连接查询数据库操作
首先需要新建一张表,为了测试随建了一张学生表 新建号一张表之后就可以对数据库进行操作了 列举了常用的增删改查 操作 static void Main(string[] args) { s ...
- android jsonarray
Json数组是子元素的有序集合,每个子元素都有一个下标,可以根据下标操纵Json数组的子元素.类JsonArray是bantouyan-json库对Json数组的抽象,提供操纵Json数组的各种方法. ...
- git gitk命令
通过gitk命令,在单独的界面上查看项目源码在各个时间点上的代码提交情况. 各个commit 各个tag ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~` 更多详细的介绍 ...
- 一步一步重写 CodeIgniter 框架 (3) —— 用面向对象重构代码
前面两篇文章为了重点突出 CodeIgniter 框架的原理,程序的结构很乱,有很多全局变量,在这一课中我们采用面向对象的方法对原先代码进行重构. 到目前为止,程序主要完成的就是 URL 分析,并根据 ...
- 关于UIText换行
话不多说,直接上代码 --代码是lua的,c++也一样 local text = ccui.Text:create("text can line wrap text can line wra ...