http://codeforces.com/contest/834
1 second
256 megabytes
standard input
standard output
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 ≤ n ≤ 109) – the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
^ >
1
cw
< ^
3
ccw
^ v
6
undefined
题意:给出开始和结束的方向,还有次数,问你是顺时针还是逆时针转到,不确定的话输出”nudefine“;
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>
#define ld long double
#define ll long long
const int inf=0x3f3f3f3f;
const int maxn=1e3+;
using namespace std;
int n;
char a,b;
int slove(char x)
{
if(x=='v')return ;
else if(x=='<')return ;
else if(x=='^')return ;
else return ;
}
int main()
{
scanf("%c %c",&a,&b);
scanf("%d",&n);
int tmp1=slove(a);
int tmp2=slove(b);
// cout<<tmp1<<" "<<tmp2<<endl;
if((tmp1+n)%==tmp2&&((tmp1-n)%+)%==tmp2)
{
printf("undefined\n");return ;
}
if((tmp1+n)%==tmp2)
{
printf("cw\n");return ;
}
if(((tmp1-n)%+)%==tmp2)
{
printf("ccw\n");return ;
}
printf("undefined\n");
return ;
}
1 second
256 megabytes
standard input
standard output
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.
There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.
For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.
Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened.
Two integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26).
In the second string, n uppercase English letters s1s2... sn are given, where si is the entrance used by the i-th guest.
Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower).
5 1
AABBB
NO
5 1
ABABB
YES
In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.
In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door.
题意:有26个们和K个门卫,给你入场顺序,看是否有某个时候至少有一扇门没有守卫;
题解:找到没扇门关闭的最后时刻然后模拟;
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>
#define ld long double
#define ll long long
const int inf=0x3f3f3f3f;
const int maxn=1e6+;
using namespace std;
char a[maxn];
int b[];
bool vis[];
int n,k;
int main()
{
scanf("%d %d",&n,&k);
scanf("%s",a);
for(int i=;i<n;i++)
{
b[a[i]-'A']=i;
}
bool flag=true;
for(int i=;i<n;i++)
{
if(!vis[a[i]-'A'])
{
k--;
vis[a[i]-'A']=true;
if(k<)
{
flag=false;break;
}
if(i==b[a[i]-'A'])k++;
}
else if(i==b[a[i]-'A'])
{
k++;
}
}
if(flag)puts("NO");
else puts("YES");
}
1 second
256 megabytes
standard input
standard output
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
In the first string, the number of games n (1 ≤ n ≤ 350000) is given.
Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly.
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
Yes
Yes
Yes
No
No
Yes
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
题意:玩游戏,开始是都是1,每轮选一个数k,一个乘k,另一个乘k^2,;给a,b两个数,看是否是某个游戏的结果;
题解:比赛当时没想用二分去找,分解因数超时了。只要a*b==x^3&&(a/x)*(b/x)==x就可以了;
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>
#define ld long double
#define ll long long
const int inf=0x3f3f3f3f;
const int maxn=1e6+;
const ll N=1e18;
using namespace std;
ll num[maxn];
int n;
ll x,y;
ll slove(ll l,ll r,ll m)
{
while(l<=r)
{
ll mid=(l+r)>>;
if(num[mid]==m)return mid;
else if(num[mid]>m)
{
r=mid-;
}
else
{
l=mid+;
}
// cout<<l<<" "<<r<<endl;
}
return -;
}
int main()
{
scanf("%d",&n);
ll cnt;
for(cnt=;cnt*cnt*cnt<=N;cnt++)
num[cnt]=cnt*cnt*cnt;
while(n--)
{
scanf("%I64d %I64d",&x,&y);
ll ans=slove(,cnt-,x*y);
if((x/ans)*(y/ans)==ans)
{
puts("Yes");
}
else
{
puts("No");
}
}
return ;
}
2.5 seconds
256 megabytes
standard input
standard output
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack cakes in boxes, and that the more distinct cake types a box contains (let's denote this number as the value of the box), the higher price it has.
She needs to change the production technology! The problem is that the oven chooses the cake types on its own and Slastyona can't affect it. However, she knows the types and order of n cakes the oven is going to bake today. Slastyona has to pack exactly k boxes with cakes today, and she has to put in each box several (at least one) cakes the oven produced one right after another (in other words, she has to put in a box a continuous segment of cakes).
Slastyona wants to maximize the total value of all boxes with cakes. Help her determine this maximum possible total value.
The first line contains two integers n and k (1 ≤ n ≤ 35000, 1 ≤ k ≤ min(n, 50)) – the number of cakes and the number of boxes, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) – the types of cakes in the order the oven bakes them.
Print the only integer – the maximum total value of all boxes with cakes.
4 1
1 2 2 1
2
7 2
1 3 3 1 4 4 4
5
8 3
7 7 8 7 7 8 1 7
6
In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2.
In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box, and three in the second box then, so the total value is 5.
题意:给你一个序列,分成K段让求每一段不同的数的数目的和最大
题解:最开始想简单了,用set贪心去做到后面发现不对,这题正确解法是dp+线段树,dp[i][j]表示分成i段在j的最大值,转移方程dp[i][j]=max(dp[i-1][j])0<j<j;可以用线段树的query直接求的
我们用last[i]代表a[i]上次出现的位置,然后每次对last[i]~i的位置全加1,代码如下
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>
#define ld long double
#define ll long long
using namespace std;
const int maxn=4e4+5e3+;
int n,k;
int a[maxn];
int now[maxn],last[maxn];
int add[maxn<<];
int dp[][maxn];
int tree[maxn<<];
void push(int rt)
{
tree[rt]=max(tree[rt<<],tree[rt<<|]);
return;
}
void push_down(int rt)
{
if(add[rt])
{
add[rt<<]+=add[rt];
add[rt<<|]+=add[rt];
tree[rt<<]+=add[rt];
tree[rt<<|]+=add[rt];
add[rt]=;
}
return ;
}
void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
tree[rt]+=c;
add[rt]+=c;
return ;
}
push_down(rt);
int m=(l+r)/;
if(L<=m)
update(L,R,c,l,m,rt<<);
if(R>m)
update(L,R,c,m+,r,rt<<|);
push(rt);
return ;
}
int query(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
return tree[rt];
}
push_down(rt);
int m=(l+r)>>;
int ans=;
if(R>m)
ans=max(ans,query(L,R,m+,r,rt<<|));
if(L<=m)
ans=max(ans,query(L,R,l,m,rt<<));
return ans;
}
int main()
{
scanf("%d %d",&n,&k);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=;i<=n;i++)
{
last[i]=now[a[i]];
now[a[i]]=i;
}
for(int i=;i<=k;i++)
{
memset(tree,,sizeof(tree));
memset(add,,sizeof(add));
for(int j=;j<=n;j++)
{
update(j,j,dp[i-][j],,n,);
}
for(int j=i;j<=n;j++)
{
update(max(i-,last[j]),j-,,,n,);
dp[i][j]=query(i-,j-,,n,);
}
}
printf("%d\n",dp[k][n]);
return ;
http://codeforces.com/contest/834的更多相关文章
- codeforces 725D . Contest Balloons(贪心+优先队列)
题目链接:codeforces 725D . Contest Balloons 先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给 ...
- codeforces.com/contest/325/problem/B
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...
- http://codeforces.com/contest/349
A. Cinema Line time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- CodeForces - 725D Contest Balloons 贪心
D. Contest Balloons time limit per test 3 seconds memory limit per test 2 ...
- http://codeforces.com/contest/555/problem/B
比赛时虽然贪了心,不过后面没想到怎么处理和set的排序方法忘了- -,其实是和优先队列的仿函数一样的... 比赛后用set pair过了... #include <bits/stdc++.h&g ...
- http://codeforces.com/contest/845
A. Chess Tourney time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- http://codeforces.com/contest/610/problem/D
D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- http://codeforces.com/contest/612/problem/D
D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- http://codeforces.com/contest/536/problem/B
B. Tavas and Malekas time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- 关于wamp服务器文件的配置
有的前端朋友想在手机端看PC端开发的html5页面,这时候会在本地PC下载一个wamp,这时候在PC端输入电脑的IP地址或者是直接输入localhost,可以访问www目录下的文件(开发项目必须放置在 ...
- PHP常量定义define与const
一.const PHP5.3以前,const只能在类内部声明变量,5.3+允许在外部声明变量,但还不能使用常量计算! const ONE = 1; const WORD = 'hello world' ...
- 移动端车牌识别ocr系统
移动端车牌识别ocr系统优点: 1.识别速度快:高度优化的车牌定位和识别算法,识别时间≤50毫秒(200万图片). 2.识别率:白天识别率≥99.7%:夜间识别率≥98%. 3.识别速度:单张图片识别 ...
- C语言中无符号数和有符号数之间的运算
C语言中无符号数和有符号数之间的运算 C语言中有符号数和无符号数进行运算(包括逻辑运算和算术运算)默认会将有符号数看成无符号数进行运算,其中算术运算默认返回无符号数,逻辑运算当然是返回0或1了. un ...
- C++学习日记(一)————类与对象
C++远征之封装篇(上)笔记 所有内容都是听课笔记,愿课堂视频如下: C++远征之封装篇(上)-慕课网http://www.imooc.com/learn/382 类和对象 1 什么是类,什么是对象 ...
- C# 导出数据到Excel模板中(转)
今天做报表的时候遇到了多表头的问题,而且相应的报表的格式都一样.所以就采用了报表模板的方式来进行. 第一步:在开发的当前项目中引入:Microsoft.Office.Interop.Excel:Sys ...
- 关于"设计模式“
夜深了,人静了,该写点儿东西了.这是第一篇博客,写点儿对设计模式的粗浅理解吧. 什么是设计模式? 上学那会儿初次听到这个名字一点儿概念都没有,不知道它是用来干嘛的,感觉听上去挺抽象的一个东西. 工 ...
- 图论中DFS与BFS的区别、用法、详解…
DFS与BFS的区别.用法.详解? 写在最前的三点: 1.所谓图的遍历就是按照某种次序访问图的每一顶点一次仅且一次. 2.实现bfs和dfs都需要解决的一个问题就是如何存储图.一般有两种方法:邻接矩阵 ...
- 提高SQL执行效率的16种方法
项目中优化sql语句执行效率的方法:1)尽量选择较小的列2)将where中用的比较频繁的字段建立索引3)select子句中避免使用'*'4)避免在索引列上使用计算.not in 和<> ...
- 201521123059 《Java程序设计》第三周学习总结
1. 本周学习总结 2. 书面作业 1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; p ...