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

留坑。


总结:

  • 尽快适应数学场。

最新文章

  1. GOF23设计模式归类
  2. vs2010中的MSBuild输出warning MSB8012问题
  3. NPOI生成单元格(列)下拉框
  4. https centos6 and 7
  5. Configuration for Python to run on Android
  6. javascript中ajax post实例详解
  7. MVC校验
  8. H5 应用程序返回button的js代码设计,设计仿stack
  9. Qt之对话框消失动画
  10. mq常用命令
  11. 学习CTF的经历-文件分析
  12. Notepad++ 安装连接服务器的NppFTP插件
  13. python+appium模拟手机物理按键操作
  14. JVM基础系列第7讲:JVM 类加载机制
  15. Qt实现半透明遮罩效果
  16. redis注册成window服务 标签: redis
  17. JVM简析
  18. PV和并发、以及计算web服务器的数量的方法
  19. BZOJ1071 [SCOI2007]压缩 其他
  20. pep8 &amp;&amp; pep20

热门文章

  1. jquery easyui datagrid翻页后再查询始终从第一页开始
  2. web自动化工具-liveStyle
  3. HTTP缓存
  4. react+redux官方实例TODO从最简单的入门(3)-- 删
  5. U3D学习笔记1: HelloWorld
  6. 小的div在大的div中垂直居中
  7. Android selecter背景选择器使用
  8. 用 javassist 来修改 class 文件
  9. MySql触发器语法总结
  10. 深入理解Web标准(网站标准)