Codeforces Round #426 (Div. 2) A B C D E

来源:互联网 发布:音乐剪辑合成软件 编辑:程序博客网 时间:2024/06/01 22:28

假装AK一场。

A. The Useless Toy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

Input

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

Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.

Examples
input
^ >1
output
cw
input
< ^3
output
ccw
input
^ v6
output
undefined
水。

#include <cstdio>#include <iostream>#include <string.h>#include <string> #include <map>#include <queue>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <cmath>#include <bitset>#define mem0(a) memset(a,0,sizeof(a))#define meminf(a) memset(a,0x3f,sizeof(a))using namespace std;typedef long long ll;typedef long double ld;const int maxn=1005,inf=0x3f3f3f3f;const ll llinf=0x3f3f3f3f3f3f3f3f; const ld pi=acos(-1.0L);char s[maxn];int main() {int n,flag=0;scanf("%s",s);char a,b;map<char,int> mp;mp['^']=1;mp['>']=2;mp['v']=3;mp['<']=4;a=mp[s[0]];scanf("%s",s);b=mp[s[0]];scanf("%d",&n);int p=b-a;while (p<0) p+=4;if (p==n%4&&n%4!=2&&n%4!=0) cout << "cw"; else if (n%4==2||n%4==0) cout << "undefined"; else cout << "ccw";return 0;}

B. The Festive Evening
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

Input

Two integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 1061 ≤ 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

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).

Examples
input
5 1AABBB
output
NO
input
5 1ABABB
output
YES
Note

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.



继续水。


#include <cstdio>#include <iostream>#include <string.h>#include <string> #include <map>#include <queue>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <cmath>#include <bitset>#define mem0(a) memset(a,0,sizeof(a))#define meminf(a) memset(a,0x3f,sizeof(a))using namespace std;typedef long long ll;typedef long double ld;const int maxn=1000005,inf=0x3f3f3f3f;const ll llinf=0x3f3f3f3f3f3f3f3f; const ld pi=acos(-1.0L);char s[maxn];int first[34],last[35];int main() {//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);    int n,k,i,j,ans,len;scanf("%d%d",&n,&k);ans=0;scanf("%s",s);len=strlen(s);memset(first,-1,sizeof(first));for (i=0;i<len;i++) {if (first[s[i]-'A']==-1) first[s[i]-'A']=i;last[s[i]-'A']=i;}ans=j=0;for (i=0;i<len;i++) {if (first[s[i]-'A']==i) j++;ans=max(ans,j);if (last[s[i]-'A']==i) j--;}if (ans<=k) cout << "NO"; else cout << "YES";return 0;}

C. The Meaningless Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

Input

In the first string, the number of games n (1 ≤ n ≤ 350000) is given.

Each game is represented by a pair of scores ab (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly.

Output

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).

Example
input
62 475 458 816 16247 9941000000000 1000000
output
YesYesYesNoNoYes
Note

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^2,给你两个数问是否可能是游戏结果。


根据题意,显然这两个数字乘起来是某个数的立方。那么只要求出立方根,判断是否是两个数的因子即可。


#include <cstdio>#include <iostream>#include <string.h>#include <string> #include <map>#include <queue>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <cmath>#include <bitset>#define mem0(a) memset(a,0,sizeof(a))#define meminf(a) memset(a,0x3f,sizeof(a))using namespace std;typedef long long ll;typedef long double ld;const int maxn=105,inf=0x3f3f3f3f;const ll llinf=0x3f3f3f3f3f3f3f3f; const ld pi=acos(-1.0L);ll gcd(ll a,ll b) {ll x,y,z;x=a;y=b;if (y>x) {x=b;y=a;}while (y) {z=x;x=y;y=z%y;}return x;}int main() {int cas;scanf("%d",&cas);while (cas--) {ll a,b,c;scanf("%I64d%I64d",&a,&b);if (a<b) swap(a,b);if (a==0||b==0) {if (a==0&&b==0) printf("Yes\n"); else printf("No\n");continue;}ll p=a*b;ll q=floor(exp(log((ld)p)/3.0L)+1e-5L);if (p==q*q*q) {if (a<=b*b&&a%q==0&&b%q==0) printf("Yes\n"); else printf("No\n");} else printf("No\n");}return 0;}



D The Bakery : 详见 http://blog.csdn.net/sinat_35406909/article/details/77714184


E. Ever-Hungry Krakozyabra
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently, a wild Krakozyabra appeared at Jelly Castle. It is, truth to be said, always eager to have something for dinner.

Its favorite meal is natural numbers (typically served with honey sauce), or, to be more precise, the zeros in their corresponding decimal representations. As for other digits, Krakozyabra dislikes them; moreover, they often cause it indigestion! So, as a necessary precaution, Krakozyabra prefers to sort the digits of a number in non-descending order before proceeding to feast. Then, the leading zeros of the resulting number are eaten and the remaining part is discarded as an inedible tail.

For example, if Krakozyabra is to have the number 57040 for dinner, its inedible tail would be the number 457.

Slastyona is not really fond of the idea of Krakozyabra living in her castle. Hovewer, her natural hospitality prevents her from leaving her guest without food. Slastyona has a range of natural numbers from L to R, which she is going to feed the guest with. Help her determine how many distinct inedible tails are going to be discarded by Krakozyabra by the end of the dinner.

Input

In the first and only string, the numbers L and R are given – the boundaries of the range (1 ≤ L ≤ R ≤ 1018).

Output

Output the sole number – the answer for the problem.

Examples
input
1 10
output
9
input
40 57
output
17
input
157 165
output
9
Note

In the first sample case, the inedible tails are the numbers from 1 to 9. Note that 10 and 1 have the same inedible tail – the number 1.

In the second sample case, each number has a unique inedible tail, except for the pair 45, 54. The answer to this sample case is going to be (57 - 40 + 1) - 1 = 17.



把一个数去掉0再把每一位排序,求[l,r]所有数这样处理后有几个不同的结果。


我们发现,最后的结果最多只有几百万个,因此可以首先构造处理后的结果,再判断是否可以由此构造[l,r]之间的数。

枚举0-9每个数的出现次数,因为出现次数相同只算一次答案。最后判断的时候,按位搜索,记录当前搜索的所有位数和l,r是否相等,记为cl,cr.

1.cl==cr==1 这时若l和r当前位置上的数相等则只能填这个数,否则如果可以找到一个(l,r)之间的数,则cl==cr==0,后面的数可以随意安排,一定可以构造成功。

2.若cl和cr其中一个为0,则按题意(大于l,小于r)进行寻找,如果只有等于l或r当前位置的数则把这个数填进去,继续搜索,如果cl==1&&cr==0&&有一个比l当前位大的数,则又转到了cl==cr==0的情况,cr==1&&cl==0的情况则同理。


#include <cstdio>#include <iostream>#include <string.h>#include <string> #include <map>#include <queue>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <cmath>#include <stack>#define mem0(a) memset(a,0,sizeof(a))#define meminf(a) memset(a,0x3f,sizeof(a))using namespace std;typedef long long ll;typedef long double ld;const int inf=0x3f3f3f3f;  const ll llinf=0x3f3f3f3f3f3f3f3f;   const ld pi=acos(-1.0L);  int cnt[10],l[20],r[20];int lenl,lenr;ll ans;inline bool check(int len,bool cl,bool cr) {if (len==0||(!cl&&!cr)) return true;int j,k;if (cl) j=l[len]; else j=0;if (cr) k=r[len]; else k=9;for (int i=j;i<=k;i++) {if (cnt[i]==0) continue;cnt[i]--;if (check(len-1,cl&&i==l[len],cr&&i==r[len])) {cnt[i]++;return true;}cnt[i]++;}return false;}inline void dfs(int num,int len) {if (num==9) {cnt[num]=len;if (check(lenr,1,1)) ans++;return;}for (int i=0;i<=len;i++) {cnt[num]=i;dfs(num+1,len-i);}} int main() {ll nl,nr;scanf("%I64d%I64d",&nl,&nr);mem0(cnt);int i;lenl=lenr=ans=0;while (nl) {l[++lenl]=nl%10;nl/=10;}while (nr) {r[++lenr]=nr%10;nr/=10;}dfs(0,lenr);printf("%I64d\n",ans);return 0;}