Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A B C D 暴力 水 二分 几何
2 seconds
256 megabytes
standard input
standard output
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string.
The first line will contain a string s consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.
Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.
VK
1
VV
1
V
0
VKKKKKKKKKVVVVVVVVVK
3
KVKV
1
For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.
题意:给你一个串 最多只能更改一个字母 问最多能有多少个“VK”
题解:暴力判断有多少个“VK” 暴力更改某一个字符为’K‘ 或’V‘ 取“VK”数量的最大值输出
#include<bits/stdc++.h>
#define ll __int64
using namespace std;
int main()
{
char a[];
scanf("%s",a);
int len=strlen(a);
int ans=;
for(int i=; i<len-; i++)
{
if(a[i]=='V'&&a[i+]=='K')
ans++;
}
for(int i=; i<len; i++)
{
int exm=;
char ww=a[i];
a[i]='V';
for(int j=; j<len-; j++)
{
if(a[j]=='V'&&a[j+]=='K')
exm++;
}
ans=max(ans,exm);
a[i]=ww;
}
for(int i=; i<len; i++)
{
int exm=;
char ww=a[i];
a[i]='K';
for(int j=; j<len-; j++)
{
if(a[j]=='V'&&a[j+]=='K')
exm++;
}
ans=max(ans,exm);
a[i]=ww;
}
printf("%d\n",ans);
return ;
}
2 seconds
256 megabytes
standard input
standard output
You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function f is another string of the same length. The i-th character of the output is equal to the minimum of the i-th character of s1 and the i-th character of s2.
For example, f("ab", "ba") = "aa", and f("nzwzl", "zizez") = "niwel".
You found two strings x and y of the same length and consisting of only lowercase English letters. Find any string z such that f(x, z) = y, or print -1 if no such string z exists.
The first line of input contains the string x.
The second line of input contains the string y.
Both x and y consist only of lowercase English letters, x and y have same length and this length is between 1 and 100.
If there is no string z such that f(x, z) = y, print -1.
Otherwise, print a string z such that f(x, z) = y. If there are multiple possible answers, print any of them. The string z should be the same length as x and y and consist only of lowercase English letters.
ab
aa
ba
nzwzl
niwel
xiyez
ab
ba
-1
The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no z such that f("ab", z) = "ba".
题意:定义 f(x, z) = y 例如 f("ab", "ba") = "aa", and f("nzwzl", "zizez") = "niwel". 等长字符串,对于每一位取出较小的合并成新的字符串。
现在给你x,y输出满足条件的z 不存在则输出-1;
题解:如果y中存在某一位字符大于x中对应位置字符 则输出-1 否则输出y
#include<bits/stdc++.h>
#define ll __int64
using namespace std;
int main()
{
char a[],b[];
scanf("%s %s",a,b);
int len=strlen(a);
for(int i=;i<len;i++)
{
if(b[i]>a[i])
{
printf("-1\n");
return ;
}
}
printf("%s\n",b);
return ;
}
2 seconds
256 megabytes
standard input
standard output
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
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
.
2 1
2 2
2 1000
2.0000000000
1 100
1 1
-1
3 5
4 3
5 2
6 1
0.5000000000
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
题意:n块电池 ai为每秒耗电量 bi为初始储电量 充电装置每秒给一个电池充p点电量 问在任意一个电池耗电完毕之前的最大持续时间
题解:二分答案 check即可 注意精度不要开大 不然会TLE;
#include<bits/stdc++.h>
#define ll __int64
using namespace std;
ll n,p;
ll a[],b[];
bool check(double x)
{
double sum=;
for(int i=;i<=n;i++)
{
if(a[i]*x-b[i]>=0.00000001)
sum+=(a[i]*x-b[i]);
}
if(sum-x*p>=0.000000001)
return true;
else
return false;
}
int main()
{
ll zong=;
scanf("%I64d %I64d",&n,&p);
for(int i=;i<=n;i++){
scanf("%I64d %I64d",&a[i],&b[i]);
zong+=a[i];
}
if(zong<=p)
{
printf("-1\n");
return ;
}
double l=,r=1e12,mid;
while(r-l>0.0001)
{
mid=(l+r)/;
if(check(mid))
r=mid;
else
l=mid;
}
printf("%f\n",mid);
return ;
}
2 seconds
256 megabytes
standard input
standard output
You are given a convex polygon P with n distinct vertices p1, p2, ..., pn. Vertex pi has coordinates (xi, yi) in the 2D plane. These vertices are listed in clockwise order.
You can choose a real number D and move each vertex of the polygon a distance of at most D from their original positions.
Find the maximum value of D such that no matter how you move the vertices, the polygon does not intersect itself and stays convex.
The first line has one integer n (4 ≤ n ≤ 1 000) — the number of vertices.
The next n lines contain the coordinates of the vertices. Line i contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th vertex. These points are guaranteed to be given in clockwise order, and will form a strictly convex polygon (in particular, no three consecutive points lie on the same straight line).
Print one real number D, which is the maximum real number such that no matter how you move the vertices, the polygon stays convex.
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
.
4
0 0
0 1
1 1
1 0
0.3535533906
6
5 0
10 0
12 -4
10 -8
5 -8
3 -4
1.0000000000
Here is a picture of the first sample

Here is an example of making the polygon non-convex.

This is not an optimal solution, since the maximum distance we moved one point is ≈ 0.4242640687, whereas we can make it non-convex by only moving each point a distance of at most ≈ 0.3535533906.
题意:给你n个点的坐标 求一个最大的d 使得任意的点向任意方向移动距离d都能保持图形为凸多边形。
题解:对于移动某一个点 是否为凸只与相邻的两个点有关 若相邻的两个点不移动则d 为当前点到 相邻两点形成的直线的距离。若相邻点移动 则d=d/2 才能保证凸多边形。所以遍历所有相邻的三个点ans=min(ans,d/2);
#include<bits/stdc++.h>
#define ll __int64
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
using namespace std;
struct point
{
double x,y;
point(double x=,double y=):x(x),y(y) {}
};
typedef point vec;
const double eps=1e-;
const double pi=acos(-1.0);
bool cmp(point a,point b)
{
if(fabs(a.x-b.x)<=eps) return a.y<b.y;
return a.x<b.x;
}
vec operator -(point a,point b)
{
return vec(a.x-b.x,a.y-b.y);
}
vec operator +(point a,point b)
{
return vec(a.x+b.x,a.y+b.y);
}
vec operator *(point a,double t)
{
return vec(a.x*t,a.y*t);
}
vec operator /(point a,double t)
{
return vec(a.x/t,a.y/t);
}
bool operator < (const point &a,const point &b)
{
return a.y<b.y || (fabs(a.y-b.y)<=eps && a.x<b.x);
}
bool operator == (const point &a,const point &b)
{
if(fabs(a.x-b.x)<=eps && fabs(a.y-b.y)<=eps)
return true;
return false;
}
int dcmp(double x)
{
if(fabs(x)<=eps) return ;
return x<?-:;
}
double cross(vec a,vec b) ///叉积
{
return a.x*b.y-a.y*b.x;
}
double dot(vec a,vec b) ///点积
{
return a.x*b.x+a.y*b.y;
}
double lentgh(vec a) ///向量长度
{
return sqrt(dot(a,a));
}
double distancetoseg(point p,point a,point b)
{
if(a==b) return lentgh(p-a);
vec v1=b-a;
vec v2=p-a;
vec v3=p-b;
if(dcmp(dot(v1,v2))<)
return lentgh(v2);
else if(dcmp(dot(v1,v3))>)
return lentgh(v3);
else
return fabs(cross(v1,v2))/lentgh(v1);
/*点到线段的距离*/
}
int main()
{
int n;
double xx[],yy[];
scanf("%d",&n);
for(int i=; i<=n; i++)
scanf("%lf %lf",&xx[i],&yy[i]);
double d=1e12;
vec q,w,e;
for(int i=; i<=n-; i++)
{
q.x=xx[i];
q.y=yy[i];
w.x=xx[i+];
w.y=yy[i+];
e.x=xx[i+];
e.y=yy[i+];
d=min(d,distancetoseg(w,q,e)/2.0);
}
q.x=xx[n-];
q.y=yy[n-];
w.x=xx[n];
w.y=yy[n];
e.x=xx[];
e.y=yy[];
d=min(d,distancetoseg(w,q,e)/2.0);
q.x=xx[n];
q.y=yy[n];
w.x=xx[];
w.y=yy[];
e.x=xx[];
e.y=yy[];
d=min(d,distancetoseg(w,q,e)/2.0);
printf("%f\n",d);
return ;
}
Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A B C D 暴力 水 二分 几何的更多相关文章
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)(A.思维题,B.思维题)
A. Vicious Keyboard time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) D. Volatile Kite
地址:http://codeforces.com/contest/801/problem/D 题目: D. Volatile Kite time limit per test 2 seconds me ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) C Voltage Keepsake
地址:http://codeforces.com/contest/801/problem/C 题目: C. Voltage Keepsake time limit per test 2 seconds ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) 题解【ABCDE】
A. Vicious Keyboard 题意:给你一个字符串,里面只会包含VK,这两种字符,然后你可以改变一个字符,你要求VK这个字串出现的次数最多. 题解:数据范围很小,暴力枚举改变哪个字符,然后c ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)
A 每次可以换一个或不换,暴力枚举位置即可 B 模拟 C 二分答案.. 边界可以优化r=totb/(tota-p),二分可以直接(r-l>=EPS,EPS不要太小,合适就好),也可以直接限定二分 ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!
Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C. Bear and Different Names 贪心
C. Bear and Different Names 题目连接: http://codeforces.com/contest/791/problem/C Description In the arm ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B - Bear and Friendship Condition 水题
B. Bear and Friendship Condition 题目连接: http://codeforces.com/contest/791/problem/B Description Bear ...
- 【树形dp】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) B. Bear and Tree Jumps
我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是, ...
随机推荐
- 1035 Password (20 分)(字符串)
注意下单复数 #include<bits/stdc++.h> using namespace std; pair<string,string>pa; int main() { ...
- Tempter of the Bone HDU 1010(DFS+剪枝)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- Weighted Median
For n elements x1, x2, ..., xn with positive integer weights w1, w2, ..., wn. The weighted median is ...
- MathExam第二次作业(升级版)
MathExamLv2——林华伟 211506319 陈珍 211406263 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实 ...
- python 动态获取当前运行的类名和函数名的方法
一.使用内置方法和修饰器方法获取类名.函数名 python中获取函数名的情况分为内部.外部,从外部的情况好获取,使用指向函数的对象,然后用__name__属性 复制代码代码如下: def a():pa ...
- P4tutorial实战
Tutorial样例实战 GitHub仓库地址 参考博客 实验一:SIGCOMM_2015/Sourse_Routing 实验环境: OS:Ubuntu16.04 bmv2:behavioral-mo ...
- HDU 1874 畅通工程续-- Dijkstra算法详解 单源点最短路问题
参考 此题Dijkstra算法,一次AC.这个算法时间复杂度O(n2)附上该算法的演示图(来自维基百科): 附上: 迪科斯彻算法分解(优酷) problem link -> HDU 1874 ...
- virtual judge 本地部署方案
这是一种将自己的电脑当作服务器来部署一个vj的方法,我也是参考前辈们的做法稍作了改动,如果在服务器上部署的话需要在细节上稍作改动: 一.什么是Virtual Judge? vj的工作原理什么? vj ...
- 团队作业4——第一次项目冲刺(Alpha版本)第一次
一.会议内容 制定任务内容 制作leangoo表格 初步工作 二.各人工作 成员 计划任务 遇见难题 贡献比 塗家瑜(组长) 后端与数据库通讯 无 1 张新磊 表设计 无 1 姚燕彬 测试计划编写 无 ...
- 3dContactPointAnnotationTool开发日志(三二)
今天就是看怎么把论文的python源码预测出来的smpl模型的姿势和形状参数弄到unity版本的smpl里,但是python版本的和unity版本的不一样. 先看看他的fit_3d.py: ...