A. Link/Cut Tree
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.

Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)

Given integers lr and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!

Input

The first line of the input contains three space-separated integers lr and k (1 ≤ l ≤ r ≤ 1018, 2 ≤ k ≤ 109).

Output

Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).

Sample test(s)
input
1 10 2
output
1 2 4 8 
input
2 4 5
output
-1
Note

Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed.

 #include <bits/stdc++.h>
using namespace std; int main()
{
long long l,r,k,m;
scanf("%I64d %I64d %I64d",&l,&r,&k);
if(k==)
{
if(k<=r && k>=l)
printf("1\n");
else
printf("-1\n");
}
else
{
m=;
int flg=;
while(m<=r)
{
if(m>=l)
{
if(flg==)
printf("%I64d",m);
else
printf(" %I64d",m);
flg=;
}
if(r/m<k)
break;
m=m*k;
}
if(flg==)
printf("-1");
printf("\n");
}
}
                B. Gena's Code
time limit per test

0.5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!

There are exactly n distinct countries in the world and the i-th country added ai tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful.

Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.

Input

The first line of the input contains the number of countries n (1 ≤ n ≤ 100 000). The second line contains n non-negative integers aiwithout leading zeroes — the number of tanks of the i-th country.

It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these number's representations doesn't exceed 100 000.

Output

Print a single number without leading zeroes — the product of the number of tanks presented by each country.

Sample test(s)
input
3
5 10 1
output
50
input
4
1 1 10 11
output
110
input
5
0 3 1 100 1
output
0
Note

In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.

In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.

In sample 3 number 3 is not beautiful, all others are beautiful.

 #include <bits/stdc++.h>
using namespace std; char a[],b[];
int num; int check()
{
int i,j,k=;
for(i=;i<strlen(a);i++)
{
if(a[i]=='' || a[i]=='')
{
if(a[i]=='')
k++;
if(k>)
return ;
}
else
return ;
}
return ;
} void cal()
{
num=num+strlen(a)-;
return ;
} int main()
{
int n,flg=;
int i,j,k;
int ch=;
num=;b[]='';
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%s",a);
if(a[]=='')
{
flg=;
}
if(flg==)
{
if(ch==)
{
if(check()==)
{
strcpy(b,a);
ch=;
continue;
}
}
cal();
}
} if(flg==)
{
printf("0\n");
return ;
}
printf("%s",b);
for(i=;i<=num;i++)
printf("");
printf("\n");
return ;
}
                C. Peter and Snow Blower
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path.

Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine.

Peter decided to tie his car to point P and now he is wondering what is the area of ​​the region that will be cleared from snow. Help him.

Input

The first line of the input contains three integers — the number of vertices of the polygon n (), and coordinates of point P.

Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line.

All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value.

Output

Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

Sample test(s)
input
3 0 0
0 1
-1 2
1 2
output
12.566370614359172464
input
4 1 -1
0 0
1 2
2 0
1 1
output
21.991148575128551812
Note

In the first sample snow will be removed from that area:

                D. Skills
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai — the current skill level. All skills have the same maximum level A.

Along with the skills, global ranking of all players was added. Players are ranked according to the so-called Force. The Force of a player is the sum of the following values:

  • The number of skills that a character has perfected (i.e., such that ai = A), multiplied by coefficient cf.
  • The minimum skill level among all skills (min ai), multiplied by coefficient cm.

Now Lesha has m hacknetian currency units, which he is willing to spend. Each currency unit can increase the current level of any skill by 1 (if it's not equal to A yet). Help him spend his money in order to achieve the maximum possible value of the Force.

Input

The first line of the input contains five space-separated integers nAcfcm and m (1 ≤ n ≤ 100 000, 1 ≤ A ≤ 109, 0 ≤ cf, cm ≤ 1000,0 ≤ m ≤ 1015).

The second line contains exactly n integers ai (0 ≤ ai ≤ A), separated by spaces, — the current levels of skills.

Output

On the first line print the maximum value of the Force that the character can achieve using no more than m currency units.

On the second line print n integers a'i (ai ≤ a'i ≤ A), skill levels which one must achieve in order to reach the specified value of the Force, while using no more than m currency units. Numbers should be separated by spaces.

Sample test(s)
input
3 5 10 1 5
1 3 1
output
12
2 5 2
input
3 5 10 1 339
1 3 1
output
35
5 5 5
Note

In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by 1.

In the second test one should increase all skills to maximum.

 #include <bits/stdc++.h>
using namespace std; struct Node
{
int v;
int id;
}a[];
long long sum[];
bool cmp(Node x,Node y)
{
return x.v<y.v;
} bool anothercmp(Node x,Node y)
{
return x.id<y.id;
} int main()
{
int i,j;
int n,Cf,Cm;
long long A,m;
while(~scanf("%d%I64d%d%d%I64d",&n,&A,&Cf,&Cm,&m)){
for(i=;i<=n;i++)
{
scanf("%d",&a[i].v);
a[i].id=i;
}
sort(a+,a+n+,cmp);
sum[]=;
for(i=;i<=n;i++)
{
sum[i]=sum[i-]+a[i].v;
}
long long ans=-,ansi,ansj,ansmi;
long long cost,remin,tmi,force;
for(i=,j=;i<=n;i++)
{
cost=A*(n-i)-(sum[n]-sum[i]);
if(cost>m)
continue;
remin=m-cost;
while(j<=i && (1ll*a[j].v*j-sum[j])<=remin)
{
j++;
}
j--;
if(i==)
{
tmi=A;
}
else
{
tmi=min((remin+sum[j])/j,A);
}
force=1ll*(n-i)*Cf+1ll*tmi*Cm;
if(force>ans)
{
ans=force;
ansi=i;
ansj=j;
ansmi=tmi;
}
} for(i=;i<=ansj;i++)
{
a[i].v=ansmi;
}
for(i=ansi+;i<=n;i++)
{
a[i].v=A;
}
sort(a+,a+n+,anothercmp);
printf("%I64d\n",ans); for(i=;i<=n;i++)
{
printf("%d ",a[i].v);
}
printf("\n"); }
return ;
}
 
                E. Necklace
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward).

Ivan has beads of n colors. He wants to make a necklace, such that it's beautiful relative to as many cuts as possible. He certainly wants to use all the beads. Help him to make the most beautiful necklace.

Input

The first line of the input contains a single number n (1 ≤ n ≤ 26) — the number of colors of beads. The second line contains after npositive integers ai   — the quantity of beads of i-th color. It is guaranteed that the sum of ai is at least 2 and does not exceed 100 000.

Output

In the first line print a single number — the maximum number of beautiful cuts that a necklace composed from given beads may have. In the second line print any example of such necklace.

Each color of the beads should be represented by the corresponding lowercase English letter (starting with a). As the necklace is cyclic, print it starting from any point.

Sample test(s)
input
3
4 2 1
output
1
abacaba
input
1
4
output
4
aaaa
input
2
1 1
output
0
ab
Note

In the first sample a necklace can have at most one beautiful cut. The example of such a necklace is shown on the picture.

In the second sample there is only one way to compose a necklace.

 #include <bits/stdc++.h>
using namespace std; int gcd(int x,int y)
{
if(x<y)
return gcd(y,x);
else if(y==)
return x;
else
return gcd(y,x%y);
} int a[]; int main()
{
int n,g;
int i,j,k,oddnum=;
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]%!=)
{
oddnum++;
k=i;
}
} if(n==)
{
printf("%d\n",a[]);
while(a[]--) printf("%c",+);
printf("\n");
return ;
}
if(oddnum>)
{
printf("0\n");
for(i=;i<=n;i++)
{
for(j=;j<=a[i];j++)
printf("%c",i+);
}
printf("\n");
}
else
{
g=a[];
for(i=;i<=n;i++)
{
g=gcd(g,a[i]);
}
printf("%d\n",g);int h=g; if(g%==)
{
while(h--)
{
for(i=;i<=n;i++)
{
if(i!=k)
for(j=;j<=a[i]/(g*);j++)
{
printf("%c",i+);
}
}
for(j=;j<=a[k]/g;j++)
printf("%c",k+);
for(i=n;i>=;i--)
{
if(i!=k)
for(j=;j<=a[i]/(g*);j++)
{
printf("%c",i+);
}
}
}
printf("\n");
}
else
{ int flg=;
while(h--)
{
if(flg==)
{
flg=;
for(i=;i<=n;i++)
{
for(j=;j<=a[i]/g;j++)
{
printf("%c",i+);
}
}
}
else
{
flg=;
for(i=n;i>=;i--)
{
for(j=;j<=a[i]/g;j++)
{
printf("%c",i+);
}
}
}
}
printf("\n");
}
}
}

Codeforces Round #339 (Div.2)的更多相关文章

  1. Codeforces Round #339 (Div. 1) A. Peter and Snow Blower 计算几何

    A. Peter and Snow Blower 题目连接: http://www.codeforces.com/contest/613/problem/A Description Peter got ...

  2. Codeforces Round #339 (Div. 2) B. Gena's Code 水题

    B. Gena's Code 题目连接: http://www.codeforces.com/contest/614/problem/B Description It's the year 4527 ...

  3. Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题

    A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...

  4. Codeforces Round #339 (Div. 1) C. Necklace 构造题

    C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...

  5. Codeforces Round #339 (Div. 1) B. Skills 暴力 二分

    B. Skills 题目连接: http://www.codeforces.com/contest/613/problem/B Description Lesha plays the recently ...

  6. Codeforces Round #339 Div.2 C - Peter and Snow Blower

    Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. A ...

  7. Codeforces Round #339 Div.2 B - Gena's Code

    It's the year 4527 and the tanks game that we all know and love still exists. There also exists Grea ...

  8. Codeforces Round #339 Div.2 A - Link/Cut Tree

    第一次正式参加常规赛想想有些小激动的呢 然后第一题就被hack了 心痛 _(:зゝ∠)_ tle点在于越界 因此结束循环条件从乘变为除 done //等等 这题没过总评 让我静静........ // ...

  9. Codeforces Round #339 (Div. 2) A

    Description Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which ...

随机推荐

  1. 一款名為com.apple.pcapd的服務

    一款名為com.apple.pcapd的服務,通過libpcap網路數據包捕獲函數包捕獲流入和流出iOS設備的HTTP數據.據紮德爾斯基稱,這一服務在所有iOS設備上都是默認啟動的,能被用來在用戶不知 ...

  2. IOS第一天多线程-05GCD队列的使用

    ************** // // HMViewController.m // 08-GCD02-队列的使用(了解) // // Created by apple on 14-9-15. // ...

  3. vba 工作案例-sheet间拷贝内容

    核心代码就是Copy Destination. Sub copy_data() ' ' copy_data 宏 ' ' Dim fzjgs() As Variant Dim cities As Var ...

  4. Example Microprocessor Register Organizations

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION

  5. JavaScript 字符 &quot;转换

    后台把一个Json类型的数据当成字符串返回到前台,但是到前台变成了下面的这个样子 "[{"name":"IE","y":72},{ ...

  6. angularJ表单验证

    常用的表单验证指令 1. 必填项验证 某个表单输入是否已填写,只要在输入字段元素上添加HTML5标记required即可: <input type="text" requir ...

  7. JS对象之间的关系

    JS对象类型 JS中,可以将对象分为"内部对象"."宿主对象"和"自定义对象"三种. 1.本地对象 ECMA-262定义为"独立于 ...

  8. SQLServer2005+附加数据库时出错提示操作系统错误5(拒绝访问)错误5120的解决办法

    SQLServer2005+ 附加数据库时出错提示操作系统错误5(拒绝访问)错误5120的解决办法 我们在用Sql SQLServer2005+附加数据库文件时弹出错误信息如下图的处理办法: 方案一: ...

  9. mongodb的一些基本操作

    1.列出所有数据库 >show dbs   2.使用数据库 >use memo   3.列出当前数据库的collections >show collections   4.显示当前正 ...

  10. angular懒加载的一些坑

    写在前面 最近在工作中接触到angular模块化打包加载的一些内容,感觉中间踩了一些坑,在此标记一下. 项目背景: 项目主要用到angularJs作为前端框架,项目之前发布的时候会把所有的前端脚本打包 ...