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. Java Native Interface 六JNI中的异常

    本文是<The Java Native Interface Programmer's Guide and Specification>读书笔记 在这里只讨论调用JNI方法可能会出现的异常, ...

  2. Java的国际化(i18n)

    http://blog.csdn.net/csuliky/article/details/4225800 1. Java国际化简介 Java既然作为一个跨平台的语言就必然要在各种不同的语言环境中使用, ...

  3. css清除浮动深度解析

    首先引入一个新的概念"包裹". float:left会使得该属性的作用容器包裹住其内部元素:那么还有么有其他属性能够产生类似于浮动这种包裹性? 答案是有的:像"浮动&qu ...

  4. ng-repeat 里 使用ng-show ng-hide出现闪动

    在项目中使用ng-repeat在表格中循环输出一组数据的时候,需要对表格中的每一列(每一列为数组的一个元素--对象)添加控制按钮. 列表样式 我的期望是 初始化 ----每一行不可编辑,保存按钮是隐藏 ...

  5. 在CentOS下搭建自己的Git服务器

    首先需要装好CentOS系统,作为测试,你可以选择装在虚拟机上,这样比较方便.这步默认你会,就不讲了.有了CentOS,那么如何搭建Git服务器呢?1.首先需要安装Git,可以使用yum源在线安装: ...

  6. c#和js互通的AES加密解密

    一.使用场景 在使用前后端分离的框架中常常会进行传输数据相互加密解密以确保数据的安全性,如web Api返回加密数据客户端或web端进行解密,或者客户端或web端进行加密提交数据服务端解密数据等等. ...

  7. MySQL延迟复制--percona-toolkit和MASTER TO MASTER_DELAY

    为了数据的安全,有的时候数据库需要延迟备份,这里说下两种延迟备份的方法. 一.借助工具. 实现环境: 192.168.189.143 (mysql主库) 192.168.189.144 (mysql备 ...

  8. Spring学习(三)

    1,Spring的事务管理机制 Spring事务管理高层抽象主要包括3个接口,Spring的事务主要是由他们共同完成的: l PlatformTransactionManager:事务管理器-主要用于 ...

  9. js 函数

    函数:封装了某一块功能 四要素: 1.返回类型 2.函数名 3.参数列表4.函数体强类型语言 返回类型 函数名 首字母大写 参数列表string(字符串) Show (int a){ 函数体 }弱类型 ...

  10. XStream xml 解析框架使用笔记

    1. xml的标签可以映射为类.类成员变量 2. 有子标签的标签映射为类,没有子标签的便签映射为类成员变量 3. 类名.类成员变量名如与标签名不一致需要通过注解或代码设置别名 // 类名 @XStre ...