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. subprocess模块还提供了很多方便的方法来使得执行 shell 命令

    现在你可以看到它正常地处理了转义. 注意 实际上你也可以在shell=False那里直接使用一个单独的字符串作为参数, 但是它必须是命令程序本身,这种做法和在一个列表中定义一个args没什么区别.而如 ...

  2. linux 解压xz包

    1.下载xz包 http://tukaani.org/xz/xz-4.999.9beta.tar.bz2   2.解压安装包 $tar -jxvf xz-4.999.9beta.tar.bz2   3 ...

  3. autoreleasepool自动释放池

     示例: @autoreleasepool { ; i[largeNumber; i++) { (因识别问题,该行代码中尖括号改为方括号代替) Person *per = [[Person alloc ...

  4. Unit06 - 抽象类、接口和内部类(下) 、 面向对象汇总

    Unit06 - 抽象类.接口和内部类(下) . 面向对象汇总 1.多态:  1)意义:    1.1)同一类型的引用指向不同的对象时,有不同的实现        行为的多态:cut().run(). ...

  5. Extjs 中column的renderer使用方法

    renderer: function(value, cellmeta, record, rowIndex, columnIndex, store) { if (record.get('productT ...

  6. java 向上转型 向下转型

    //父类 四边形 class Quadrangle{ public static void draw (Quadrangle q){ } } //子类  public class Parallelog ...

  7. vmware centos下配置ip

    使用NAT模式 虚拟机网络连接使用NAT模式,物理机网络连接使用Vmnet8. 虚拟机设置里面--网络适配器,网络连接选择NAT模式. 虚拟机菜单栏-编辑-虚拟网络编辑器,选择Vmnet8 NAT模式 ...

  8. 移动端网站或APP点击后出现闪动或灰色背景(转)

    遇到这个问题了,记录下,备用~ 文章来源:http://www.lxway.com/846165591.htm --------------------------- 隐藏文本框阴影:(去除文本框默认 ...

  9. 湖大OJ-实验E----可判定的DFA的空问题

    实验E----可判定的DFA的空问题 Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB Total submit ...

  10. 微软 .net 你更新这么快IDE vs2015 、语法糖 6.0、framework、‘吹得这么牛,然并用

    好久没写吐槽文章了,因为无尽的加班,也因为工作的变迁,又因为最近看了微软又尼玛发布什么什么,好受不了. 今年大专毕业第八个年头了,人也到了30,真是光阴荏苒啊.最近这一两年发生了很多事,让我自己倍受打 ...