A. (a, b)-Tower

当指数大于模数的时候用欧拉定理递归计算,否则直接暴力计算。

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<iostream>
using namespace std;
typedef long long LL;
int pw(int x,int y,int mod){
int ret=1;
for(int i=0;i<y;i++){
ret=1LL*ret*x%mod;
}
return ret;
}
int solve(int l,int r,int p){
if(l==1)return 1;
if(l==r){
return l%p;
}
int phi=0;
for(int i=1;i<=p;i++)if(__gcd(p,i)==1)phi++;
return pw(l,solve(l+1,r,phi)+phi,p);
}
int main(){
freopen("abtower.in","r",stdin);
freopen("abtower.out","w",stdout);
int a,b;
while(scanf("%d%d",&a,&b)!=EOF){
printf("%d\n",solve(a,b,10));
}
}

  

B. Bridges Construction

留坑。

C. Equivalence Relation

留坑。

D. Formula-1

留坑。

E. Ideal Photo

三分第一个人的位置即可。

#include <bits/stdc++.h>
using namespace std ; const int MAXN = 205 ;
int n;
vector<int>V;
double check(double x){
double ret=0;
for(int i=0;i<V.size();i++){
ret+=sqrt(1.0+1.0*(V[i]-x-i)*(V[i]-x-i));
}
return ret;
}
void solve () {
V.clear();
for(int i=1;i<=n;i++){
int x;scanf("%d",&x);
V.push_back(x);
}
for(int i=1;i<=n;i++){
int x;scanf("%d",&x);
V.push_back(x);
}
sort(V.begin(),V.end());
double l=-3e6;
double r=3e6;
for(int i=0;i<300;i++){
double l1=l+(r-l)/3,l2=l+(r-l)/3*2;
double t1=check(l1),t2=check(l2);
if(t1>t2)l=l1;else r=l2;
}
double ans=check(l);
//printf("%.12f %.12f\n",l,r);
printf("%.12f\n",ans);
//for(double l=-5;l<=5;l+=0.1)printf("%.12f\n",check(l));
} int main () {
freopen ( "make-a-row.in" , "r" , stdin ) ;
freopen ( "make-a-row.out" , "w" , stdout ) ;
while ( ~scanf ( "%d" , &n ) ) solve () ;
return 0 ;
}

  

F. (p, q)-Knight

首先通过exgcd求出一组可行解,然后暴力调整若干项即可。

#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<time.h>
#include<assert.h>
#include<iostream>
using namespace std;
typedef long long LL;
typedef pair<int,int>pi;
const LL Inf=1LL<<60;
LL exgcd(LL a,LL b,LL &x,LL &y){
if(!b)return x=1,y=0,a;
LL d=exgcd(b,a%b,y,x);
y-=a/b*x;return d;
}
LL ans;
void up(LL &x,LL y){if(x>y)x=y;}
void check(LL t1,LL t2,LL x,LL y){
if(abs(t1%2)!=abs(x%2))return;
if(abs(t2%2)!=abs(y%2))return;
up(ans,max(abs(t1),abs(x))+max(abs(t2),abs(y)));
//if(x==10&&y==-3)printf("val=%lld\n",max(abs(t1),abs(x))+max(abs(t2),abs(y)));
//if(x==10&&y==-3)printf("t1=%lld t2=%lld ans=%lld\n",t1,t2,ans);
}
int main(){
freopen("pqknight.in","r",stdin);
freopen("pqknight.out","w",stdout);
LL p,q;
while(scanf("%lld%lld",&p,&q)!=EOF){
if(p>q)swap(p,q);
if(p==0){
puts(q==1?"1":"-1");
continue;
}
if(p==1){
if(q%2==1)puts("-1");
else printf("%lld\n",q+1);
continue;
}
if(__gcd(p,q)!=1){
puts("-1");
continue;
}
LL x,y;
LL t1=p,t2=q;
exgcd(p,q,x,y);
//printf("x=%lld y=%lld\n",t1,t2);
ans=Inf;
for(int i=-2;i<=2;i++){
check(t1,t2,x+i*q,y-i*p);
}
x=-x,y=-y;
for(int i=-2;i<=2;i++){
check(t1,t2,x+i*q,y-i*p);
}
if(ans==Inf){
puts("-1");
}
else printf("%lld\n",ans);
}
return 0;
}

  

G. Random Wormholes

如果能到1,那么直接走过去,否则随机走向下一个点。

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<iostream>
using namespace std;
typedef long long LL; int main(){
//freopen("abtower.in","r",stdin);
//freopen("abtower.out","w",stdout);
while(1){
LL RAND=(1LL<<32)-1;
printf("1\n");
fflush(stdout);
string s;
cin>>s;
if(s=="yes"){break;}
while(1){
LL x=(rand()%65536)*65536LL+rand()%65536;
printf("%lld\n",x);
fflush(stdout);
cin>>s;
if(s=="yes")break;
}
}
}

  

H. Second Maximum

分段积分。

#include <bits/stdc++.h>
using namespace std ; const int MAXN = 205 ;
int n;
vector<int>V;
int l[55],r[55];
double a[55];
double b[55];
void mul(double t0,double t1){
memset(b,0,sizeof b);
for(int i=0;i<=n+1;i++){
if(i)b[i]+=a[i-1]*t1;
b[i]+=a[i]*t0;
}
for(int i=0;i<=n+1;i++)a[i]=b[i];
}
void solve () {
double ans=0;
V.clear();
for(int i=0;i<n;i++){
scanf("%d%d",l+i,r+i);
V.push_back(l[i]);
V.push_back(r[i]);
}
sort(V.begin(),V.end());
V.erase(unique(V.begin(),V.end()),V.end());
for(int it=0;it<V.size()-1;it++){
int curl=V[it],curr=V[it+1];
for(int i=0;i<n;i++){
if(r[i]<=curl)continue;
memset(a,0,sizeof a);
a[0]=1;
//if(curr>l[i])mul((curr+0.0)/(r[i]-l[i]),1.0/(l[i]-r[i]));
bool flag=1;
for(int j=0;j<n;j++){
if(i==j)continue;
if(curr<=l[j]){flag=0;break;}
if(curl<r[j]){
mul((l[j]+0.0)/(l[j]-r[j]),1.0/(r[j]-l[j]));
}
}
if(!flag)continue;
/*
if(it==1&&i==0){
puts("wa");
for(int j=0;j<=n;j++)printf("%.2f ",a[j]);puts("");
}
*/
a[0]=0;
for(int j=1;j<=n;j++)a[j]*=j;
if(curr>l[i])mul((r[i]+0.0)/(r[i]-l[i]),1.0/(l[i]-r[i]));
for(int j=1;j<=n+1;j++)a[j]/=j+1;
double rr=curr*curr,ll=curl*curl;
for(int j=1;j<=n+1;j++){
ans+=a[j]*(rr-ll);
rr=rr*curr;
ll=ll*curl;
}
//printf("it=%d i=%d ans=%.2f\n",it,i,ans);
}
}
printf("%.12f\n",ans);
}
int main(){
freopen("secondmax.in","r",stdin);
freopen("secondmax.out","w",stdout);
while(~scanf("%d",&n))solve();
}

  

I. Ticket To Ride

留坑。


总结:

  • 尽快适应数学场。

XVI Open Cup named after E.V. Pankratiev. GP of Peterhof的更多相关文章

  1. XVI Open Cup named after E.V. Pankratiev. GP of Ukraine

    A. Associated Vertices 首先求出SCC然后缩点,第一次求出每个点能到的点集,第二次收集这些点集即可,用bitset加速,时间复杂度$O(\frac{nm}{64})$. #inc ...

  2. XVI Open Cup named after E.V. Pankratiev. GP of Siberia

    A. Passage 枚举两个点,看看删掉之后剩下的图是否是二分图. #include <bits/stdc++.h> using namespace std ; const int MA ...

  3. XVI Open Cup named after E.V. Pankratiev. GP of Ekaterinburg

    A. Avengers, The 留坑. B. Black Widow 将所有数的所有约数插入set,然后求mex. #include<bits/stdc++.h> using names ...

  4. XVI Open Cup named after E.V. Pankratiev. GP of Eurasia

    A. Nanoassembly 首先用叉积判断是否在指定向量右侧,然后解出法线与给定直线的交点,再关于交点对称即可. #include<bits/stdc++.h> using names ...

  5. XVI Open Cup named after E.V. Pankratiev. GP of SPB

    A. Bubbles 枚举两个点,求出垂直平分线与$x$轴的交点,答案=交点数+1. 时间复杂度$O(n^2\log n)$. #include<cstdio> #include<a ...

  6. XVI Open Cup named after E.V. Pankratiev. GP of Ekaterinburg--I.Iron man

    n个服务器,k类任务,每个服务器完成一个任务都有特定的花费$cost_{i,j}$,但是你设置好某台机器去完成某项任务时他只能去完成这类任务,除非你可以花费$C$去更改配置.第$i$天要求去完成$q_ ...

  7. XV Open Cup named after E.V. Pankratiev. GP of Tatarstan

    A. Survival Route 留坑. B. Dispersed parentheses $f[i][j][k]$表示长度为$i$,未匹配的左括号数为$j$,最多的未匹配左括号数为$k$的方案数. ...

  8. XVII Open Cup named after E.V. Pankratiev. GP of SPb

    A. Array Factory 将下标按前缀和排序,然后双指针,维护最大的右边界即可. #include<cstdio> #include<algorithm> using ...

  9. XIV Open Cup named after E.V. Pankratiev. GP of SPb

    A. Bracket Expression 直接按题意模拟即可. 时间复杂度$O(n)$. #include<stdio.h> #include<algorithm> #inc ...

随机推荐

  1. zookeeper_service 出错 java.lang.NoClassDefFoundError: org/I0Itec/zkclient/exception/ZkNoNodeException

    2016-12-18 08:28:07 ContextLoader:358 ERROR - Context initialization failed java.lang.NoClassDefFoun ...

  2. JavaScript 日期选择器 Pikaday

    找一些插件的过程实在太痛苦了...好容易找到一个,赶紧记录下.免得以后重复浪费时间在这上面. 插件名:Pikaday github地址:https://github.com/dbushell/Pika ...

  3. 关于angularjs指令

    一个指令用来引入新的HTML语法.指令是DOM元素上的标记,使元素拥有特定的行为.举例来说,静态的HTML不知道如何来创建和展现一个日期选择器控件.让HTML能识别这个语法,我们需要使用指令.指令通过 ...

  4. 全排列算法的JS实现

    问题描述:给定一个字符串,输出该字符串所有排列的可能.如输入“abc”,输出“abc,acb,bca,bac,cab,cba”. 虽然原理很简单,然而我还是折腾了好一会才实现这个算法……这里主要记录的 ...

  5. Entity Framework 简单查询

    前言 首先来简单的复习一下如何使用Code First. 第一步还是先建立一个控制台的应用程序,然后通过Nuget添加Entity Framework.那么同时会给packages.config和Ap ...

  6. nova instance出错:"message": "Proxy error: 502 Read from server failed

    执行 $ nova resize instance1 时候出错: {, "details": " File \"/opt/stack/nova/nova/com ...

  7. Team Foundation Server源代码管理多人开发的使用心得

    问题1:多人使用TFS源代码管理器的时候,往往会造成同个文件内源代码不一致,覆盖别人的代码. 解决方案: 给多个人分配不同的开发任务,保证每个人修改的文件都不会重叠. 但有些情况无法避免多个人同时修改 ...

  8. OC与Swift单例

    OC: +(instancetype)shareNetworkTools{ static id instance; static dispatch_once_t onceToken; //onceTo ...

  9. Android笔记:蓝牙

    if (!BTAdapter.isEnabled()) { //没有打开,就启动确认窗口询问用户是否打开 Intent i = new Intent(BluetoothAdapter.ACTION_R ...

  10. UML大战需求分析——阅读笔记04

    读<UML大战需求分析>有感04 开发某系统的重要前提是: 这个系统有谁在用? 这些人通过这个系统能做什么事? 一般搞清楚这件事,再画个业务流程图,就能条例清楚的表达系统的需求了.作为一个 ...