codeforces Round#381 div2
第一题:
按余数分类,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的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- 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 ...
- 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 ...
随机推荐
- bzoj1616
水水啊,直接搜就行,不过bfs好像会mle(一定是我太菜了QAQ) #include<iostream> #include<algorithm> #include<cst ...
- 微信小程序之明源商城系列-01-商城介绍及开发准备
1,效果展示 数据来自于写的一个小爬虫爬了明源商城部分的数据.由于价格的保密性,下列产品价格和真实的都不同. 1.1 主页及开发文件结构 1.2 产品的详细页面 1.2 产品分类页面 1.3 产品 ...
- linux下centos的网络连接
- 创建ServiceArea
/// <summary> /// Services the area. /// </summary> /// <param name="networkData ...
- 【转】Java enum的用法详解
用法一:常量 在JDK1.5 之前,我们定义常量都是: public static fianl.... .现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举提供了比常量更多的方法. p ...
- [Unity] Shader - CG语言 和 HLSL语言
CG 跟 HLSL几乎是一摸一样的. (HLSL官方参考,包含语法格式,函数库,关键字,在这个地方: http://msdn.microsoft.com/en-us/library/bb509638( ...
- windows7下修改hosts文件无效解决办法(转)
通常会为了开发方便.或者屏蔽掉一些恶意网站,我们会在hosts(c:\windows\system32\drivers\etc\hosts)文件中进行相应的域名指向,例:
- yaf学习资料
yaf学习资料 文档 鸟哥的官方文档 Yaf框架结合PHPUnit的集成测试 php yaf框架扩展实践六--单元测试.计划任务.第三方库等 php yaf框架扩展实践一--配置篇 yaf实战例子 y ...
- Android ViewPager sharedpreferences
http://www.cnblogs.com/dwinter/archive/2012/02/27/AndroidViewPager%E5%A4%9A%E9%A1%B5%E9%9D%A2%E6%BB% ...
- tyvj1089 smrtfun
背景 广东汕头聿怀初中 Train#2 Problem3 描述 现有N个物品,第i个物品有两个属性A_i和B_i.在其中选取若干个物品,使得sum{A_i + B_i}最大,同时sum{A_i},s ...