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 ...
随机推荐
- 在eclipse中部署jsp项目
昨天在做实验的时候发现图片的路径不对,怎么改都不对,后来想到在浏览器中输入localhost:8080是tomcat服务器的路径,没找到资源是不是就是项没有部署到tomcat中,去tomcat的web ...
- SpringBoot源码解析:AOP思想以及相应的应用
spring中拦截器和过滤器都是基于AOP思想实现的,过滤器只作用于servlet,表现在请求的前后过程中:拦截器属于spring的一个组件,由spring管理, 可以作用于spring任何资源,对象 ...
- IndentationError: unindent does not match any outer indentation level
[problem] 从别处copy过来的python代码经过自己改动后,运行出错 [解决过程] vim file :set list # cat -A file 也可以 可以看到9-12行的inde ...
- mysql命令总结
统计全库数据量: use information_schema; SELECT TABLE_NAME, (DATA_LENGTH) as DataM , (INDEX_LENGTH) as Index ...
- Tp-link TL-WR841N无线路由器端口映射到外网如何设置
针对TP-LINK的无线路由器进行演示如何设置端口映射和访问控制,演示使用的具体型号是TP-LINK TL-WR841N 3G无线路由器如何设置端口映射. 什么是端口映射? 端口映射又称端口转发,有的 ...
- thinkphp语言包
1.config.php语言包相关配置. //开启语言包 'LANG_SWITCH_ON' => true, 'LANG_AUTO_DETECT' => true, // 自动侦测语言 开 ...
- 浏览器内核控制Meta标签说明文档
浏览器内核控制Meta标签说明文档 原文链接 背景介绍 由于众所周知的情况,国内的主流浏览器都是双核浏览器:基于Webkit内核用于常用网站的高速浏览.基于IE的内核用于兼容网银.旧版网站.以360的 ...
- spring mvc统一异常处理(@ControllerAdvice + @ExceptionHandler)
spring 封装了非常强大的异常处理机制.本文选取@ControllerAdvice + @ExceptionHandler 这种零配置(全注解),作为异常处理解决方案! @ControllerAd ...
- Python_DB_Api
python DB API 内容 建立连接connection 数据库交互对象cursor 数据库异常类exception 流程 创建connection 获取cursor 执行查询.执行命令.获取数 ...
- HDU 3966 Aragorn's Story 树链剖分
Link: http://acm.hdu.edu.cn/showproblem.php?pid=3966 这题注意要手动扩栈. 这题我交g++无限RE,即使手动扩栈了,但交C++就过了. #pragm ...