Codeforces Round #381 (Div. 2) 复习倍增//
刷了这套题 感触良多
我想 感觉上的差一点就是差很多吧 。
每次都差一点 就是差很多了。。。
不能气馁。。要更加努力去填补那一点点。 老天不是在造物弄人,而是希望你用更好的自己去迎接自己。
A. Alyona and copybooks
有n本书 还需要买k本使得(n+k)%4==0
有三种 一本 a元 两本 b元 三本 c元的 不能分开卖
问至少花多少
枚举一下即可 。。。 我居然一开始搞了个dp记录买1-4本的最优策略....还wa了....
#include <stdio.h>
#include <iostream>
#include <algorithm>
//#include <>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 2e5+;
ll v[];
int main()
{
int n;
cin>>n;
for(int i=;i<=;i++)
cin>>v[i];
ll ans = LONG_LONG_MAX;
for(int i=;i<=;i++)
for(int j=;j<=;j++)
for(int k=;k<=;k++)
{
if((n+i+j*+k*)%==)
{
ans = min(ans,i*v[]+j*v[]+k*v[]);
}
}
cout<<ans<<endl;
return ;
}
AC代码
B. Alyona and flowers
给你m个区间 问选任意的区间使得和最大
发现区间和为负不要选就好
#include <stdio.h>
#include <iostream>
#include <algorithm>
//#include <>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 2e5+;
ll v[];
int main()
{
int n,k;
cin>>n>>k;
for(int i=;i<=n;i++)
{ cin>>v[i];
v[i]+=v[i-];
}
ll ans = ;
while(k--)
{
int x;int y;
cin>>x>>y;
ll val = v[y] - v[x-];
if(val>) ans+=val;
}
cout<<ans<<endl;
return ;
}
AC代码
C. Alyona and mex
给你长度为n的序列和m个区间,为区间中没出现过的最小的非负整数最大是多少。
那么区间最短的那个决定ans
接下来我们按照
[0,ans-1]这样循环填充n个位置。这样的话在任意的区间内都有[0,ans-1]
这个很机智啊。。。。
#include <stdio.h>
#include <iostream>
#include <algorithm>
//#include <>
#include <vector>
using namespace std;
typedef long long ll; int main()
{
int n,k;
cin>>n>>k;
int ans = INT_MAX;
for(int i=;i<k;i++)
{
int x;int y;
cin>>x>>y;
if((y-x)<ans)
{
ans = y-x;
}
}
ans++;
cout<<ans<<endl;
for(int i=;i<n;i++)
{
printf("%d ",i%ans);
}
return ;
}
AC代码
D.倍增LCA
想一想 MK一下
Codeforces Round #381 (Div. 2) 复习倍增//的更多相关文章
- 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 #549 (Div. 2) E 倍增处理按排列顺序的上一个位置
https://codeforces.com/contest/1143/problem/E 题意 p为n的一个排列,给出有m个数字的数组a,q次询问,每次询问a数组区间[l,r]中是否存在子序列为p的 ...
- 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 ...
- 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 ...
- Codeforces Round #381 (Div. 2) C. Alyona and mex(无语)
题目链接 http://codeforces.com/contest/740/problem/C 题意:有一串数字,给你m个区间求每一个区间内不含有的最小的数,输出全部中最小的那个尽量使得这个最小值最 ...
- Codeforces Round #381(div 2)
A.(分类讨论) 题意:你有n本书,有三种买书方案,花a元买1本,花b元买2本,花c元买3本,问最少花多少钱,使得你书的总数是4的倍数 分析:分类讨论的题,但是要注意你可以买超过4本书--可以买5本. ...
- Codeforces Round #381 (Div. 2) A B C 水 构造
A. Alyona and copybooks time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #381 (Div. 2)D. Alyona and a tree(树+二分+dfs)
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is ...
随机推荐
- URL Regex expression
转载: http://blog.csdn.net/weasleyqi/article/details/7912647 首先,正则表达式: String check = @"((http|ft ...
- Django中提示TemplateDoesNotExist?
用的是1.9版本.需要在settings.py文件中设置TEMPLATES下的DIRS如下: TEMPLATES = [ { 'BACKEND': 'django.template.backends. ...
- Delegate, Method as Parameter.
代理, 将方法作为另一方法的参数. 类似C里面的函数指针. using System; using System.Windows.Forms; using System.Threading; name ...
- JVM & Server & Connector & Context Relationship
- jQuery.ajax()调用asp.net后台方法
利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法.介意方法名不要重名 建一个WebFormAjax名aspx文件 CS <%@ Page Language=" ...
- iOS10 权限适配
权限适配 这应该算iOS10系统适配的范畴,最近这两个都在弄,所以就直接和Xcode8适配一起写出来了. 在iOS10之后需要在Info.plist中,添加新的字段获取权限,否则在iOS10上运行会导 ...
- spring3 项目更新
列志华 (组长) http://www.cnblogs.com/liezhihua/ 团队guihub https://github.com/LWHTF/OrderingFood 黄柏堂 http:/ ...
- 关于web前端开发学习的顺序
学习web前端开发该怎么学,按照什么顺序学习,这是很多新手朋友会遇到的问题.下面简单的说一下.由于在国内大学课程里面,几乎没有前端开发这门课程,无非就是一些网页设计之类的课程,但那些课程无论是老师讲还 ...
- 向IPython Notebook中导入.py文件
IPython Notebook使用起来简洁方便,但是有时候如果需要导入一个现有的.py文件,则需要注意选择导入的方法以达到不同的效果.目前遇到3种方法. (1) 将文件保存为.ipynb格式,直接拖 ...
- 为 Linux 应用程序编写 DLL[转]
自:http://www.ibm.com/developerworks/cn/linux/sdk/dll/index.html 在仅仅只会编写插件的时候为什么要编写整个应用程序? 插件和 DLL 通常 ...