Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) 题解【ABCDE】
A. Vicious Keyboard
题意:给你一个字符串,里面只会包含VK,这两种字符,然后你可以改变一个字符,你要求VK这个字串出现的次数最多。
题解:数据范围很小,暴力枚举改变哪个字符,然后check就好。
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int ans = 0;
for(int i=0;i<s.size();i++){
if(s[i]=='V'){
s[i]='K';
}else
s[i]='V';
int tmp = 0;
for(int j=0;j<s.size()-1;j++){
if(s[j]=='V'&&s[j+1]=='K')
tmp++;
}
ans=max(ans,tmp);
if(s[i]=='V')
s[i]='K';
else
s[i]='V';
}
int tmp = 0;
for(int j=0;j<s.size()-1;j++){
if(s[j]=='V'&&s[j+1]=='K')
tmp++;
}
ans=max(ans,tmp);
cout<<ans<<endl;
}
B. Valued Keys
题意:定义f(x,y),表示选择字符串中字典序最小的那个字符,然后现在你需要构造一个b,满足f(a,b)=c
题解:如果c[i]>a[i],那么就显然非法,否则b[i]=c[i]即可。
#include<bits/stdc++.h>
using namespace std;
int main(){
string a,b,c;
cin>>a>>b;
for(int i=0;i<a.size();i++){
if(b[i]>a[i]){
cout<<"-1"<<endl;
return 0;
}else
c+=b[i];
}
cout<<c<<endl;
}
C. Voltage Keepsake
题意:你有个充电器,每秒钟可以充p的电。然后你有n个装置,每个装置每秒钟增加a[i],一开始有b[i]。请问最多多少秒,可以使得每一个装置都能运作下去。
题解:显然的二分答案,呈现单调性。然后我们贪心的去充电即可。注意二分的姿势应该是枚举二分的次数。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
double a[maxn],b[maxn],p;
int n;
bool check(double x){
double las=x*p;
for(int i=0;i<n;i++){
if(b[i]+las<a[i]*x)return false;
if(b[i]>=a[i]*x)continue;
las-=(a[i]*x-b[i]);
}
return true;
}
int main(){
cin>>n>>p;
for(int i=0;i<n;i++)
cin>>a[i]>>b[i];
//cout<<check(2)<<endl;
double l = 0,r = 1e15;
for(int i=0;i<150;i++){
double mid = (l+r)/2.0;
if(check(mid))l=mid;
else r=mid;
//cout<<l<<" "<<r<<endl;
}
if(l>=1e14){
cout<<"-1"<<endl;
}else{
printf("%.10f\n",l);
}
}
D. Volatile Kite
题意:问你凸包上每个点最多移动多少,可以使得这个凸包仍然是一个凸包。
题解:答案就是p[i]这个点,离p[i-1],p[i+1]点的距离,最小值除以2。至于答案为什么这个,我就猜了一发结论,然后交一发就过了。。。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+6;
struct node{
double x,y;
}p[maxn];
int n;
double dis(node A,node B){
return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
double area(node A,node B,node C){
double l1 = dis(A,B);
double l2 = dis(B,C);
double l3 = dis(A,C);
double p = (l1+l2+l3)/2.0;
return sqrt(p*(p-l1)*(p-l2)*(p-l3));
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
cin>>p[i].x>>p[i].y;
}
double ans = 1e15;
for(int i=0;i<n;i++){
ans = min(ans,area(p[i],p[(i+1)%n],p[(i-1+n)%n])*2/dis(p[(i+1)%n],p[(i-1+n)%n]));
}
printf("%.12f\n",ans/2.0);
//cout<<ans/2<<endl;
}
C. Vulnerable Kerbals
题意:你需要构造一个最长的序列,满足以下要求:
1.前缀乘积在%m的情况下,应该都不一样。
2.规定的n个数,不能在前缀乘积中出现。
3.序列中的每个数都应该是[0,m)的。
题解:假设gcd(a,m)%gcd(b,m)==0,那么就显然会存在一个k,使得ak%m=b。那么这道题就按照gcd分类,然后用dp求一个最长路,然后再解同余方程,求解每一个k即可。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
vector<int> P[maxn],E[maxn];
int n,m,vis[maxn],dp[maxn],from[maxn],phi[maxn];
int gcd(int a,int b){
if(b==0)return a;
return gcd(b,a%b);
}
long long qpow(long long a,long long b,long long c){
long long res = 1;
while(b){
if(b&1)res=res*a%c;
a=a*a%c;
b>>=1;
}
return res;
}
void pre(){
for(int i=1;i<maxn;i++){
phi[i]+=i-1;
for(int j=2*i;j<maxn;j+=i){
phi[j]-=phi[i];
}
}
}
int main(){
pre();
scanf("%d%d",&n,&m);
if(m==1){
cout<<"1\n0\n"<<endl;
return 0;
}
for(int i=1;i<=n;i++){
int x;scanf("%d",&x);
vis[x]=1;
}
for(int i=0;i<m;i++){
if(vis[i])continue;
P[gcd(i,m)].push_back(i);
}
int mx = 0;
for(int i=m;i>0;i--){
from[i]=-1;
for(int j=2*i;j<m;j+=i){
if(dp[j]>dp[i]){
dp[i]=dp[j];
from[i]=j;
}
}
dp[i]+=P[i].size();
if(dp[i]>dp[mx]){
mx=i;
}
}
if(vis[0]==0)dp[mx]++;
cout<<dp[mx]<<endl;
int last = 1;
while(mx!=-1){
for(int i=0;i<P[mx].size();i++){
int x = P[mx][i];
int g = gcd(last,x);
g = gcd(g,m);
cout<<(x/g)*qpow((last/g),phi[m/g]-1,m/g)%(m/g)<<" ";
last=x;
}
mx=from[mx];
}
if(vis[0]==0)cout<<"0";
cout<<endl;
}
Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) 题解【ABCDE】的更多相关文章
- 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)
A 每次可以换一个或不换,暴力枚举位置即可 B 模拟 C 二分答案.. 边界可以优化r=totb/(tota-p),二分可以直接(r-l>=EPS,EPS不要太小,合适就好),也可以直接限定二分 ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A B C D 暴力 水 二分 几何
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 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的整数倍,还要加上多少. 于是, ...
随机推荐
- 移植BOA服务器到开发板
移植BOA 服务器到GEC210 开发板 开发平台主机:VMWare--Ubuntu 10.04 LTS开发板:GEC210 / linux-2.6.35.7编译器:arm-linux-gcc-4.5 ...
- [学习笔记]JS 数组Array push相关问题
前言: 今天用写了一个二维数组,都赋值为零,然后更新其中一个值,结果和预期是不一样,会整列的相同位置都是同一个值. 1.用Chrome的控制台样例如下: arrs[2][2] =1的赋值,竟然是三个数 ...
- pytest十:用例 a 失败,跳过测试用例 b 和 c 并标记失败 xfail
当用例 a 失败的时候,如果用例 b 和用例 c 都是依赖于第一个用例的结果,那可以直接跳过用例 b 和 c 的测试,直接给他标记失败 xfail用到的场景,登录是第一个用例,登录之后的操作 b 是第 ...
- Unicode转义序列
声明: web前端学习笔记,欢迎大神指点.联系QQ:1522025433. Javascipt 定义了一种特殊序列,使用6位ASCII字符代表任意16Unicode内码.这些Unicode转义序列均以 ...
- 20155309南皓芯 网络对抗《网络攻防》 Exp1 PC平台逆向破解(5)M
实践目标 本次实践的对象是linux的可执行文件 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串. 该程序同时包含另一个代码片段,getShell,会返回一个可 ...
- ASP.NET Core 2 学习笔记(九)模型绑定
ASP.NET Core MVC的Model Binding会将HTTP Request数据,以映射的方式对应到参数中.基本上跟ASP.NET MVC差不多,但能Binding的来源更多了一些.本篇将 ...
- poj 2485 求最小生成树中 最长的一条边
Sample Input 1 //T 3 //n0 990 692 //邻接矩阵990 0 179692 179 0Sample Output 692 prim # include <iostr ...
- hdu 4549 M斐波拉契 (矩阵快速幂 + 费马小定理)
Problem DescriptionM斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = aF[1] = bF[n] = F[n-1] * F[n-2] ( n > 1 ) 现在 ...
- thinkphp获取ip地址及位置信息
ThinkPHP\Common\funcitons.php下有一个get_client_ip()能够获取ip地址 但是有时候不够准确 找到了下面一段来 function get_client_ip($ ...
- 和组合数有关的dp
1. UVaLive 7143 Room Assignment 用dp[i][r]表示,前i个盒子已经放完了,手上还拿着r对同色球. 状态转移方程为:dp[i+1][r-a-b] = dp[i][r] ...