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&#39;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&#39;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 ...
随机推荐
-
签名、BOM头、编码、Windows记事本编码、java编码解码的那些事
对于Windows记事本: ANSI :GB2312 java中应使用GBK解码 Unicode :有签名的UTF-16LE java中应使用UTF-16解码 Unicode big endian : ...
-
SqlServer阅读收集
1.根据字段名,查找相关表--INFORMATION_SCHEMA.COLUMNS SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME ...
-
C# Dictionary和Dynamic类型
开发中需要传递变参,考虑使用 dynamic 还是 Dictionary(准确地说是Dictionary<string,object>).dynamic 的编码体验显著优于 Diction ...
-
POJ 1005 解题报告
1.题目描述 2.解题思路 好吧,这是个水题,我的目的暂时是把poj第一页刷之,所以水题也写写吧,这个题简单数学常识而已,给定坐标(x,y),易知当圆心为(0,0)时,半圆面积为0.5*PI*(x ...
-
Linux学习笔记19——信号2
上一节中讲到了sigprocmask函数,它的作用是检查或修改它的进程信号掩码,这一节我们主要学习捕捉与忽略信号的函数sigaction和等待信号函数. 一 sigaction函数的作用 定义在接收 ...
-
POj3421 X-factor Chains(质因数分解+排列组合)
POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...
-
ZZNU 1992: 情人节的尴尬
题目描述 情人节这不刚过去没多久吗,我得给大家爆个料.这个事关于小飞飞的,小飞飞呢,要给她女票买礼物,但是呢有个比较尴尬的事情,小飞飞有些钱在某宝里,有些钱在某东里,众所周知,这俩可是死对头,想相互转 ...
-
jsp base标签与meta标签学习小结
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...
-
PMI-ACP练习题知识积累-打印版
敏捷铁三角的参数:价值,质量,约束.传统的铁三角包括的参数是范围,进度和成本 敏捷计划的三个主要层级为:发布计划,迭代计划,每日计划 敏捷开发模型的特征包括 开发由多个迭代组成. 敏捷拥抱不确定性,而 ...
-
python 判断是否是空行或注释行
#coding:utf-8 '''''cdays-4-exercise-6.py 文件基本操作 @note: 文件读取写入, 列表排序, 字符串操作 @see: 字符串各方法可参考hekp(str)或 ...