Codeforces Round #339 (Div.2)
2 seconds
256 megabytes
standard input
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 l, r 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!
The first line of the input contains three space-separated integers l, r and k (1 ≤ l ≤ r ≤ 1018, 2 ≤ k ≤ 109).
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).
1 10 2
1 2 4 8
2 4 5
-1
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");
}
}
0.5 seconds
256 megabytes
standard input
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.
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.
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
3
5 10 1
50
4
1 1 10 11
110
5
0 3 1 100 1
0
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 ;
}
2 seconds
256 megabytes
standard input
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.
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.
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 .
3 0 0
0 1
-1 2
1 2
12.566370614359172464
4 1 -1
0 0
1 2
2 0
1 1
21.991148575128551812
In the first sample snow will be removed from that area:
2 seconds
256 megabytes
standard input
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.
The first line of the input contains five space-separated integers n, A, cf, cm 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.
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.
3 5 10 1 5
1 3 1
12
2 5 2
3 5 10 1 339
1 3 1
35
5 5 5
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 ;
}
2 seconds
256 megabytes
standard input
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.
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.
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.
3
4 2 1
1
abacaba
1
4
4
aaaa
2
1 1
0
ab
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)的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题
A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...
- Codeforces Round #339 (Div. 1) C. Necklace 构造题
C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...
- Codeforces Round #339 (Div. 1) B. Skills 暴力 二分
B. Skills 题目连接: http://www.codeforces.com/contest/613/problem/B Description Lesha plays the recently ...
- 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 ...
- 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 ...
- Codeforces Round #339 Div.2 A - Link/Cut Tree
第一次正式参加常规赛想想有些小激动的呢 然后第一题就被hack了 心痛 _(:зゝ∠)_ tle点在于越界 因此结束循环条件从乘变为除 done //等等 这题没过总评 让我静静........ // ...
- Codeforces Round #339 (Div. 2) A
Description Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which ...
随机推荐
- Linux启动过程
系统BIOS是当你点击开机键是第一个运行的程序.1. 首先主板需要接收到一个稳定的电源供给信号.如果没有得到稳定的电源供给系统自动关闭.2. 当接受到一个稳定的电源供给信号,处理器会启动,当处理器启动 ...
- ASCII码
ASCII(pronunciation: /ˈæski/ ASS-kee,American Standard Code for Information Interchange,美国信息交换标准代码)是 ...
- Apache Spark技术实战之6 -- spark-submit常见问题及其解决
除本人同意外,严禁一切转载,徽沪一郎. 概要 编写了独立运行的Spark Application之后,需要将其提交到Spark Cluster中运行,一般会采用spark-submit来进行应用的提交 ...
- 推荐《HeadFirst设计模式》
相对于国内初版的<大话设计模式>,HeadFirst真的是更好的选择,虽然看起来很厚.很吓人,但对于初学者而言浅显易懂.直击要点,即使对设计模式熟悉的同学去读这本书相信也有很大的收获.用了 ...
- hibernate学习(3)——api详解对象(2)
1. Transaction 事务 事务的操作: 开启事务 beginTransaction() 获得事务 getTransaction() 提交事务:commit() 回滚事务:rollback ...
- c语言中的指针问题
“*”符号的作用在C语言中有两种: 1.声明该变量是指针,例如:int * p;//表示声明一个int类型的指针,变量名为p 2.在指针运算时,表示取这个地址上的内容,例如 temp = *p;// ...
- react-native win7环境搭建
时间:2016-08-22 晚,西安 1.安装jdk java version "1.6.0_45"Java(TM) SE Runtime Environment (build 1 ...
- define宏定义和const常变量区别
1.define是宏定义,程序在预处理阶段将用define定义的内容进行了替换.因此程序运行时,常量表中并没有用define定义的常量,系统不为它分配内存.const定义的常量,在程序运行时在常量表中 ...
- easyui combobox级联(转载)
一.创建combobox 有如下几种方式可以创建一个combobox 1.使用select标签,并加上class="easyui-combobox",这种方式比较适用于静态的选项. ...
- SQL-乐观锁,悲观锁之于并发
每次写博客,第一句话都是这样的:程序员很苦逼,除了会写程序,还得会写博客!当然,希望将来的一天,某位老板看到此博客,给你的程序员职工加点薪资吧!因为程序员的世界除了苦逼就是沉默.我眼中的程序员大多都不 ...