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 ...
随机推荐
- Python基础灬异常
异常&异常处理 异常!=错误 在程序运行过程中,总会遇到各种各样的错误. 有的错误是程序编写有问题造成的,比如本来应该输出整数结果输出了字符串,这种错误我们通常称之为bug,bug是必须修复的 ...
- New York Comic Con 2013 - 2013年纽约动漫展
New York Comic Con - 2013年纽约动漫展 New York Comic Con is the largest pop culture event on the East Coas ...
- MySQL case when 使用
case when 自定义排序时的使用 根据 case when 新的 sort字段排序 case when t2.status = 4 and t2.expire_time>UNIX_TIME ...
- GitHub 的简单使用
GitHub 的简单使用 2016-01-28 16:32:481909浏览1评论 一.Git 版本控制器 commit:做一个版本:commit new file:添加到版本中,下边填的是项目的描述 ...
- “Hello World!”团队第七次Scrum立会
"Hello world!"团队召开第七次Scrum立会.博客内容: 1.会议时间 2.会议成员 3.会议地点 4.会议内容 5.Todo list 6.会议照片 7.燃尽图 一. ...
- 简易四则运算生成程序——添加GUI支持
项目成员:张金生 张政 工程地址: https://coding.net/u/jx8zjs/p/paperOne/git ssh://git@git.coding.net:jx8zjs/pap ...
- 小程序获取 openid 和 session_key
<?php //获取openid function getopenid(){//获取用户ID //code为前端通过 wx.login() 方式获取 $code = $_GET["co ...
- 使用java程序模拟页面发送http的post请求
在web应用程序中,一般都是通过页面发送http的post请求,但也可以使用java程序来模拟页面发送请求,代码如下: import java.io.BufferedReader; import ja ...
- 虚拟机中安装 centOS,本地安装 SSH 连接 - 02
先进入 centOS 中,查询虚拟机的 IP 地址: 双击打开 SSH 可视化客户端: 点击 Connect 需要输入之前那个[无论如何都要使用]的密码. 密码在[centOS - 01]里面设置过, ...
- SpringMVC 应知应会
springMVC 是表现层技术,可以用来代替 struts2,下面是简略图:主要是处理器和视图,只有这两个部分需要编写代码. springMVC 三大组件:处理器映射器,处理器适配器,视图解析器. ...