Codeforces Round #416 (Div. 2)A B C 水 暴力 dp
2 seconds
256 megabytes
standard input
standard output
At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving each other one candy more than they received in the previous turn.
This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
Single line of input data contains two space-separated integers a, b (1 ≤ a, b ≤ 109) — number of Vladik and Valera candies respectively.
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
1 1
Valera
7 6
Vladik
Illustration for first test case:
Illustration for second test case:
题意:给你两个数 a,b 按照 1 2 3 4 ...i a b轮流减少相应的i值 若a先减少到0 输出Vladik 反之输出Valera
题解:水
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#define ll __int64
using namespace std;
int main()
{
int a,b;
scanf("%d %d",&a,&b);
int s=,d=;
s=sqrt(a);
for(int i=sqrt(b);;i--)
{
if(i*(i+)<=b)
{
d=i;
break;
}
}
// cout<<s<<" "<<d<<endl;
if(s<=d)
printf("Vladik\n");
else
printf("Valera\n");
return ;
}
2 seconds
256 megabytes
standard input
standard output
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Yes
No
Yes
Yes
No
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Yes
No
Yes
No
Yes
Explanation of first test case:
- [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
- [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
- [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
- [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
- [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
题意:给你一个长度为n的序列p m个查询 将[l,r] 升序排列 判断px是否改变 如果没有改变输出Yes 否则输出No
题解:遍历判断当前区间 小于px的数的数量;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#define ll __int64
using namespace std;
int n,m;
int a[];
int main(){
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int l,r,x;
for(int i=;i<=m;i++){
scanf("%d %d %d",&l,&r,&x);
int jishu=;
for(int j=l;j<=r;j++)
{
if(a[j]<=a[x])
jishu++;
}
if(jishu==(x-l+))
printf("Yes\n");
else
printf("No\n");
}
return ;
}
2 seconds
256 megabytes
standard input
standard output
Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:
Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code ai is known (the code of the city in which they are going to).
Train chief selects some number of disjoint segments of the original sequence of people (covering entire sequence by segments is not necessary). People who are in the same segment will be in the same train carriage. The segments are selected in such way that if at least one person travels to the city x, then all people who are going to city x should be in the same railway carriage. This means that they can’t belong to different segments. Note, that all people who travel to the city x, either go to it and in the same railway carriage, or do not go anywhere at all.
Comfort of a train trip with people on segment from position l to position r is equal to XOR of all distinct codes of cities for people on the segment from position l to position r. XOR operation also known as exclusive OR.
Total comfort of a train trip is equal to sum of comfort for each segment.
Help Vladik to know maximal possible total comfort.
First line contains single integer n (1 ≤ n ≤ 5000) — number of people.
Second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 5000), where ai denotes code of the city to which i-th person is going.
The output should contain a single integer — maximal possible total comfort.
6
4 4 2 5 2 3
14
9
5 1 3 1 5 2 4 2 5
9
In the first test case best partition into segments is: [4, 4] [2, 5, 2] [3], answer is calculated as follows: 4 + (2 xor 5) + 3 = 4 + 7 + 3 = 14
In the second test case best partition into segments is: 5 1 [3] 1 5 [2, 4, 2] 5, answer calculated as follows: 3 + (2 xor 4) = 3 + 6 = 9.
题意:给出n,然后n个数,要你选择一些不相交的区间,使得这些区间中出现的数字的异或的和最大,区间有这样的限制,对于区间的任何数,其余相同的数都要在这个区间,否者这个区间就是不合法的。
题解:求出每个数出现的最左端和最右端,定义dp[i]为1到i这个区间所能选出的最大值,然后枚举右端点,找合法的左端点即可
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#define ll __int64
using namespace std;
int n;
ll a[];
int l[],r[];
ll we[][];
ll dp[];
int mp[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
l[a[i]]=n;
r[a[i]]=;
}
for(int i=;i<=n;i++){
l[a[i]]=min(l[a[i]],i);
r[a[i]]=max(r[a[i]],i);
}
for(int i=;i<=n;i++){
memset(mp,,sizeof(mp));
we[i][i]=a[i];
mp[a[i]]=;
int sum=a[i];
for(int j=i+;j<=n;j++){
if(mp[a[j]]==){
sum=sum^a[j];
mp[a[j]]=;
}
we[i][j]=sum;
}
}
dp[]=;
for(int i=;i<=n;i++){
if(r[a[i]]==i){
int L=l[a[i]];
int what=;
for(int j=l[a[i]]+;j<r[a[i]];j++){
if(r[a[j]]>i){
what=;
break;
}
L=min(L,l[a[j]]);
}
if(what==)
dp[i]=max(dp[i-],dp[L-]+we[L][i]);
else
dp[i]=dp[i-];
}
else
dp[i]=dp[i-];
}
printf("%I64d\n",dp[n]);
return ;
}
Codeforces Round #416 (Div. 2)A B C 水 暴力 dp的更多相关文章
- Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #127 (Div. 1) D. Brand New Problem 暴力dp
D. Brand New Problem 题目连接: http://www.codeforces.com/contest/201/problem/D Description A widely know ...
- Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #407 (Div. 2)A B C 水 暴力 最大子序列和
A. Anastasia and pebbles time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #401 (Div. 2) A B C 水 贪心 dp
A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...
- 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 #297 (Div. 2)D. Arthur and Walls 暴力搜索
Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- Codeforces Round #267 (Div. 2) C. George and Job(DP)补题
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...
- 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 ...
随机推荐
- JavaScript事件冒泡和捕获
事件捕获指的是从document到触发事件的那个节点,即自上而下的去触发事件. 事件冒泡是自下而上的去触发事件. 绑定事件方法的第三个参数,就是控制事件触发顺序是否为事件捕获.true,事件捕获:fa ...
- 该用哪个:Redis与Memcached之间如何选择呢?
华为云分布式缓存Redis5.0和Memcached都是华为云DCS的核心产品. 那么在不同的使用场景之下,如何选择Redis5.0和Memcached呢? 就由小编为大家进行详细的数据对比分析吧 R ...
- 使用 Mesos 管理虚拟机
摘要 为了满足渲染.基因测序等计算密集型服务的需求,UCloud 推出了“计算工厂”产品,让用户可以快速创建大量的计算资源(虚拟机).该产品的背后,是一套基于 Mesos 的计算资源管理系统.本文简要 ...
- 运维学习笔记(七)之T02-01计算机网络 、 数制 、 网络通信参考模型
计算机网络 计算机网络概述 什么是计算机网络 硬件方面:通过线缆将网络设备和计算机连接起来 软件方面:操作系统.应用软件.应用程序通过通信线路互连 实现资源共享.信息传递 功能 数据通信/资源共享/增 ...
- RequestMappingHandlerMapping 详解
我们先理简单梳理一个关系 关系梳理 spring ioc 是spring的核心,用来管理spring bean的生命周期 MVC 是一种使用 MVC(Model View Controller 模型- ...
- 【第四周】psp
代码累计 300+575+475+353=1603 随笔字数 1700+3000+3785+4210=12695 知识点 QT框架 Myeclipse基础环境 代码复用,封装 Ps技术 在excel画 ...
- $(document).click() 在苹果手机上不能正常运行解决方案
本来是如下一段跳转代码,发现在安卓和微信开发者工具上都能正常运行,但是苹果手机就不行了. $(document).on('click', '.url', function(){ location.hr ...
- matlab 图像Mat类型矩阵中的值(uint8)类型转换,防止溢出
a=[50,60,70; 80,90,50; 100,55,40] 假设a是一个灰度图的mat形式(当然实际的size肯定比这大,我只是举例子),如果需要对这个矩阵的像素进行加减处理,很可能会产生溢出 ...
- sqlserver-触发器-判断更新了哪个字段。
create trigger 触发器名称on 表名(将触发器创建到那张表中)for updateasif update(判断更新字段)beginupdate (要更新的表名) set 字段=inser ...
- MVC中ajax提交表单示例
页面中: @using (Ajax.BeginForm("Login", "User", new AjaxOptions() { HttpMethod = &q ...