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

  1. 二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers

    题目传送门 /* 题意:一个汉堡制作由字符串得出,自己有一些原材料,还有钱可以去商店购买原材料,问最多能做几个汉堡 二分:二分汉堡个数,判断此时所花费的钱是否在规定以内 */ #include < ...

  2. 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 ...

  3. Codeforces Round #218 (Div. 2) C. Hamburgers

    C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. 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 ...

  5. Codeforces Round #218 (Div. 2) C题

    C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #218 (Div. 2) (线段树区间处理)

    A,B大水题,不过B题逗比了题意没理解清楚,讲的太不清楚了感觉= =还是英语弱,白白错了两发. C: 二分答案判断是否可行,也逗比了下...二分的上界开太大导致爆long long了...   D: ...

  7. 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 ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. 设计模式 ( 十四 ) 迭代器模式Iterator(对象行为型)

      设计模式 ( 十四 ) 迭代器模式Iterator(对象行为型) 1.概述 类中的面向对象编程封装应用逻辑.类,就是实例化的对象,每个单独的对象都有一个特定的身份和状态.单独的对象是一种组织代码的 ...

  2. THUSC2015

    这些题目在BZOJ上面有,可惜是权限题.话说BZOJ上面的题目真的挺好的,要不是我穷,早就去弄个号了! 言归正传,今年的题目难度可以由一个名人名言看出: 题目太水.--某某神犇 可是我掂量了一下,发现 ...

  3. Java NIO与IO

    当学习了Java NIO和IO的API后,一个问题立即涌入脑海: 我应该何时使用IO,何时使用NIO呢?在本文中,我会尽量清晰地解析Java NIO和IO的差异.它们的使用场景,以及它们怎样影响您的代 ...

  4. TCP三次握手和四次挥手具体解释

    三次握手:建立TCP须要三次握手才干建立, 先Client端发送连接请求报文,Server段接受连接后回复ACK报文,并为这次连接分配资源.Client端接收到ACK报文后也向Server段发生ACK ...

  5. Lucene核心--构建Lucene搜索(上篇,理论篇)

    2.1构建Lucene搜索 2.1.1 Lucene内容模型 一个文档(document)就是Lucene建立索引和搜索的原子单元,它由一个或者多个字段(field)组成,字段才是Lucene的真实内 ...

  6. 梳理一下重装sql2008R2sp1步骤

    我的电脑是这样,最早的时候装的是2005,后来公司用到2008,我就手动卸载,但是好像卸载的不够彻底,在装2008的时候,选择升级方式安装. 虽然成功了,但是在运行select @@version 时 ...

  7. STSR round#1

    乱搞玩出新高度.....#1

  8. Java--CyclicBarrier使用简介

    CyclicBarrier介绍 (一)一 个同步辅助类,它允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point).在涉及一组固定大小的线程的程序中,这些线程必须不时 ...

  9. 演练2-2:Guestbook示例应用程序

    为使Guestbook应用程序有用,我们需要为用户提供一些提交数据的方式,将这些数据存储起来,以便稍后进行查看.为了达到这一目标,我们打算对应用程序添加一个数据库,将其作为该留言簿的后台存储库. 1. ...

  10. 仿OpenStack开发云计算管理软件

    仿OpenStack开发云计算管理软件 使用Python语言开发一套类似OpenStack的云计算管理平台LouCloud,具备基本的用户,服务器,镜像与 虚拟机管理功能,学习IaaS,虚拟化,Lib ...