第一题:

按余数分类,1,2,3分别由哪些基数组成

1—>[1][2+3][3+3+3]

2—>[1+1][2][3+3]

3—>[1+1+1][1+2][3]

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn=2e5+20;
const ll MAX=0x7fffffffffffffff;
int main ()
{
ll n,a,b,c;
ll cost=MAX;
cin>>n>>a>>b>>c;
if(n%4==0)
cout<<"0"<<endl;
else
{
int tmp=4-n%4;
if(tmp==1)
{
cost=min(a,b+c);
cost=min(cost,c+c+c);
}
if(tmp==2)
{
cost=min(b,a+a);
cost=min(cost,c+c);
}
if(tmp==3)
{
cost=min(a+a+a,b+a);
cost=min(cost,c);
}
cout<<cost<<endl;
}
return 0;
}

第二题:

选出子序列和为正的项

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn=2e5+20;
const int MAX=0x7fffffff;
int a[102];
int b[102],c[102];
int main ()
{
int n,m,l,r,ans=0;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
int t=0;
while(m--)
{
cin>>l>>r;
int sum=0;
for(int i=l;i<=r;i++)
{
sum+=a[i];
}
if(sum>0)//子序列和为正
{
b[t]=l;
c[t]=r;
t++;
}
}
if(t==0)
{
cout<<'0';
return 0;
}
else
{
for(int i=1;i<=n;i++)
{
int num=0;
for(int j=0;j<t;j++)
{
if(i>=b[j]&&i<=c[j])num++;
}
ans+=num*a[i];
} }
cout<<ans<<endl;
return 0;
}

第三题:

构造法,寻找在一个区间未出现的最小整数。那么我们可以先求出   区间长度的最小值MIN

然后构造   0 1 2 3....MIN-1   0 1 2 .....这样构造的话 区间长度大于MIN的mex肯定不小于MIN

#include<stdio.h>
#include<algorithm>
#include<string.h>
typedef __int64 ll;
using namespace std;
int main()
{
int n,m,i,l,r,MIN=1000005;
int a[100005];
scanf("%d%d",&n,&m);
for(i=1;i<=m;i++)
{
scanf("%d%d",&l,&r);
MIN=min(r-l+1,MIN);
}
printf("%d\n",MIN);
for(i=1;i<=n;i++)
if(i!=n)
printf("%d ",i%MIN);
else
printf("%d\n",i%MIN);
return 0;
}

codeforces Round#381 div2的更多相关文章

  1. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  2. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  3. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  4. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  5. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  6. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

  7. CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...

  8. Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 前缀和

    B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree ...

  9. Codeforces Round #381 (Div. 1) A. Alyona and mex 构造

    A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother want ...

随机推荐

  1. [转]Java compiler level does not match解决方法

    查看链接:http://jingyan.baidu.com/article/95c9d20da3ec5fec4e756186.html

  2. angular作用域分析

    angualr作用域 Scope 控制器作用域的继承特性Ⅰ 绑定的数据是变量 单向隔离(兄弟之间互不影响,父子之间单向继承) 父级控制器的数据绑定会影响到子级控制器 前提是子控制器内没有绑定数据 单向 ...

  3. Java Web的web.xml文件作用及基本配置(转)

    其实web.xml就是asp.net的web.config一个道理. 说明: 一个web中完全可以没有web.xml文件,也就是说,web.xml文件并不是web工程必须的. web.xml文件是用来 ...

  4. Hibernate的关联映射关系

    一:多对一 <many-to-one 1.name:当前类的属性名(关联映射的类) 2.column:属性多对应的类的对应的表的外键(连接条件) 3.class:属性所对应的类的权限定名 4.n ...

  5. 线程间通信 GET POST

    线程间通信有三种方法:NSThread   GCD  NSOperation       进程:操作系统里面每一个app就是一个进程. 一个进程里面可以包含多个线程,并且我们每一个app里面有且仅有一 ...

  6. Win7普通版-X86-SP1-ios-旗舰版安装

    ------------------------------- 自己的电脑是X64Win7系统.Acer电脑----->>现在改装成  Win7普通版-X86-SP1-ios-旗舰版安装 ...

  7. Java Web学习笔记3

    今天做了一个实验:Servlet访问WEB-INF目录下的文件notice.html 最后始终不能出现预期的效果,我猜想可能是使用了Tomcat 8版本的原因吧,暂时放下,等以后知识丰富了,再来解决它 ...

  8. HTML补充

    补充一: 让DIV 自动居中 width:980px;margin:0 auto; 补充二: 内敛标签: inline #块级标签转换成内联标签. block #变成块级. inline-block ...

  9. Zookeeper的安装和使用

    首先在Zookeeper官网下载最新版本,下载后解压到用户目录下. tar -zxvf zookeeper-3.4.8.tar.gz 重命名conf目录下zoo_sample.cfg文件为zoo.cf ...

  10. Beanutils基本用法

    Beanutils用了魔术般的反射技术,实现了很多夸张有用的功能,都是C/C++时代不敢想的.无论谁的项目,始终一天都会用得上它.我算是后知后觉了,第一回看到它的时候居然错过. 1.属性的动态gett ...