第一题:

按余数分类,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. [转]<jsp:include>和<%@include%>的区别

    首先,转发自yangbobo1992的 <jsp:include>和<%@include%>的区别 这个是我见过写的最好的之一 <%@include%>和<j ...

  2. Unity 难点目录

    1.mesh的任意切割.(难点) 2.扇形区域识别玩家.(解决) 3.NGUI横滑同时竖滑,或滑动同时点击冲突处理.(解决)

  3. backup mysql

    #!/bin/bashcd /home/Licw/backup_openDBNow=$(date +"%m-%d-%Y--%H:%M:%S")#echo $NowFile=$Now ...

  4. BZOJ2728: [HNOI2012]与非

    线性基乱搞,非正解= = #include<cstdio> int n,m; typedef long long ll; ll l[60],j,s,t; void up(ll& i ...

  5. sql 从一个库中取某个表的数据导入到另一个库中相同结构的表中

    sql 2008 从一个库中把 某个表中的数据导入到另一个库中的具有相同结构的表中 use 库1 go insert into  库1.dbo.表1  select * from  库2.dbo.表1 ...

  6. 深入理解springAOP

    概念:AOP(Aspect-Oriented Programming)即面向切面编程.它是对传统的OOP(面向对象)编程的一种补充,在OOP中往往一个对象有什么行为我们就定义什么方法,对象与对象之间存 ...

  7. WinForm窗体代码结构优化

    选择系统新建WinForm程序,会生成FormMain.cs/ FormMain.Designer.cs/ FormMain.resx 当我们发现系统生成的FormMain.cs里面代码太多的时候,不 ...

  8. EF唯一索引

    this.Property(p => p.Name) .IsRequired() .HasMaxLength()) .HasColumnAnnotation("Index", ...

  9. Python之路【第二十篇】其他WEB框架

    WEB框架功能分析 WEB框架本质上,就是一个SOCKET Server WEB框架前面有WSGI或者是自己写的SOCKET,然后交给URL路由系统处理,然后交给某个函数或某个类,然后在模板里拿到模板 ...

  10. svn 版本转为git

    git clone 相当于git init 和 git svn fetch.git svn rease git svn fetch 从svn服务器取指定区间的版本转化成git库 git svn reb ...