Codeforces Round #381 (Div. 2) A B C 水 构造
1 second
256 megabytes
standard input
standard output
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks.
What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.
The only line contains 4 integers n, a, b, c (1 ≤ n, a, b, c ≤ 109).
Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4.
1 1 3 4
3
6 2 1 1
1
4 4 4 4
0
999999999 1000000000 1000000000 1000000000
1000000000
In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.
In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total.
In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything.
In the fourth example Alyona should buy one pack of one copybook.
题意:1件的费用为a 2件的费用为b 3件的费用为c 现在已经拥有n件物品 购买另外k件 使得(n+k)%4==0 输出最小的花费
题解;水 共有9种策略
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll __int64
#define mod 10000000007
using namespace std;
ll n,a,b,c;
int main()
{
scanf("%I64d %I64d %I64d %I64d",&n,&a,&b,&c);
if(n%==)
{
printf("0\n");
}
else
{
int exm=-n%;
if(exm==)
{
printf("%I64d\n",min(a,min(b+c,*c)));
}
if(exm==)
{
printf("%I64d\n",min(*a,min(b,c*)));
}
if(exm==)
{
printf("%I64d\n",min(*a,min(b+a,c)));
}
}
return ;
}
2 seconds
256 megabytes
standard input
standard output
Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.
For example, consider the case when the mother has 5 flowers, and their moods are equal to 1, - 2, 1, 3, - 4. Suppose the mother suggested subarrays (1, - 2), (3, - 4), (1, 3), (1, - 2, 1, 3). Then if the girl chooses the third and the fourth subarrays then:
- the first flower adds 1·1 = 1 to the girl's happiness, because he is in one of chosen subarrays,
- the second flower adds ( - 2)·1 = - 2, because he is in one of chosen subarrays,
- the third flower adds 1·2 = 2, because he is in two of chosen subarrays,
- the fourth flower adds 3·2 = 6, because he is in two of chosen subarrays,
- the fifth flower adds ( - 4)·0 = 0, because he is in no chosen subarrays.
Thus, in total 1 + ( - 2) + 2 + 6 + 0 = 7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!
Alyona can choose any number of the subarrays, even 0 or all suggested by her mother.
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100).
The next m lines contain the description of the subarrays suggested by the mother. The i-th of these lines contain two integers li and ri(1 ≤ li ≤ ri ≤ n) denoting the subarray a[li], a[li + 1], ..., a[ri].
Each subarray can encounter more than once.
Print single integer — the maximum possible value added to the Alyona's happiness.
5 4
1 -2 1 3 -4
1 2
4 5
3 4
1 4
7
4 3
1 2 3 4
1 3
2 4
1 1
16
2 2
-1 -2
1 1
1 2
0
The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays.
题意:给你n个数 m个区间 在这m个区间中取若干个区间 对于选择的区间求和累加 输出最大值
题解:水 对于某个区间 若区间和大于0则累加否则舍弃
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define ll __int64
#define mod 10000000007
using namespace std;
int n,m;
int a[];
int sum[];
int b[];
int l,r;
int main()
{
scanf("%d %d",&n,&m);
sum[]=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
}
for(int i=;i<=m;i++)
{
scanf("%d %d",&l,&r);
b[i]=sum[r]-sum[l-];
}
sort(b+,b++m);
int ans=;
for(int i=m;i>=;i--)
ans=ans+max(,b[i]);
printf("%d\n",ans);
return ;
}
2 seconds
256 megabytes
standard input
standard output
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
The first line contains two integers n and m (1 ≤ n, m ≤ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri(1 ≤ li ≤ ri ≤ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
In the first line print single integer — the maximum possible minimum mex.
In the second line print n integers — the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
5 3
1 3
2 5
4 5
2
1 0 2 1 0
4 2
1 4
2 4
3
5 2 0 1
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5)is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
题意:要求你构造一个长度为n的数列 给你m个区间 某个区间的mex值=当前区间内没有出现过的最小的非负数 要求构造的数列中 区间mex的最小值尽可能大
题解:找到给定区间的最小长度 len 构造一个 0 1 2...len-1 0 1 2...len-1...的数列 满足题目要求 并且mex值的最小值为len
为说明问题 对于题目的样例一
5 3
1 3
2 5
4 5
得出的结果为
0 1 0 1 0
试验证
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define ll __int64
#define mod 10000000007
using namespace std;
int n,m;
int ans[];
int l[],r[];
int main()
{
scanf("%d %d",&n,&m);
int exm=;
for(int i=;i<=m;i++)
{
scanf("%d %d",&l[i],&r[i]);
exm=min(exm,r[i]-l[i]);
}
for(int i=;i<=n;i++)
ans[i]=;
for(int i=;i<=n;i++)
{
for(int j=;j<=exm;j++)
{
if(i+j<=n)
{
ans[i+j]=j;
}
}
i=i+exm;
}
printf("%d\n",exm+);
for(int i=;i<=n;i++)
printf("%d ",ans[i]);
printf("\n");
return ;
}
Codeforces Round #381 (Div. 2) A B C 水 构造的更多相关文章
- 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 ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #285 (Div. 2) A, B , C 水, map ,拓扑
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- 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. 2) D. Alyona and a tree 树上二分+前缀和思想
题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsm ...
- Codeforces Round #381 (Div. 2) D dfs序+树状数组
D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- OC中用NSSortDescriptor对象进行数组排序
//创建一个数组 NSArray *array = @[@"one", @"two", @"three", @"four" ...
- SpringMVC 处理数据模型
处理模型数据 Spring MVC 提供了以下几种途径输出模型数据: ModelAndView: 处理方法返回值类型为 ModelAndView 时, 方法体即可通过该对象添加模型数据 Map 及 M ...
- aspx文件为什么会慢
你可以在 global.asax 的 Application_Start 方法中写一个日志,例如写 C# code ? 1 2 3 4 5 void Application_Start(objec ...
- iframe 简单的一个用法 局部调用
<iframe id="main_com" name="main_com" width="100%" height="750 ...
- iOS App 获取从后台返回前台时的页面
产品美美的给小伙伴提了一个需求,当程序从后台进入前台时,如果是指定的页面,则弹出提示框. 大家首先想到的方法就是通过 AppDelegate.h 进行控制,相对复杂的步骤就是 在程序进入后台时对当前页 ...
- <script type="text/javascript" src="<%=path %>/pages/js/arsis/area.js?v=1.01"></script> 为什么在最后加? v+1.01
不写也可以 是为了js改变以后 ,名字未变 ,如果原来有的浏览器加载 了,遇到相同名字的就是引用缓存,不在从新加载.会出现错误.加上后 会重新加载. css 引用后面也一样.
- 关于GridView的第一个item图片加载不出来问题
首先感谢csdn里的id 大神了没 的博客 地址:http://blog.csdn.net/wenyiqingnianiii/article/details/39291667 原因在positi ...
- VMware10 安装centos6.7 设置NAT模式
最近刚开始学Linux运维.我看的书是<跟阿铭学Linux>,视频教程里面使用NAT模式手动分配IP可以成功ping通网关,但是我照着视频一步一步操作却一直不成功,不知道是什么原因,昨天弄 ...
- fzu2028
//Accepted 7324 KB 203 ms /* source:fzu2028 time :2015.5.29 by :songt */ /*题解: 树链剖分 单点更新,求路径和 */ #in ...
- MFC绘制图片闪烁详解
用MFC如何高效地绘图 显示图形如何避免闪烁,如何提高显示效率是问得比较多的问题. 而且多数人认为MFC的绘图函数效率很低,总是想寻求其它的解决方案. MFC的 ...