传送门

$cf$ 自闭了,打 $abc$ 散散心

A - 9x9

...这个有什么好讲的吗,题目看懂就会做了

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. typedef long long ll;
  8. inline int read()
  9. {
  10. int x=,f=; char ch=getchar();
  11. while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
  12. while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
  13. return x*f;
  14. }
  15. int a,b;
  16. int main()
  17. {
  18. a=read(),b=read();
  19. if(a>||b>||a<||b<) { printf("-1\n"); return ; }
  20. printf("%d\n",a*b);
  21. return ;
  22. }

A

B - 81

预处理一下哪些数可以被表示然后查表即可

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. typedef long long ll;
  8. inline int read()
  9. {
  10. int x=,f=; char ch=getchar();
  11. while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
  12. while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
  13. return x*f;
  14. }
  15. const int N=;
  16. bool vis[N];
  17. int main()
  18. {
  19. for(int i=;i<=;i++)
  20. for(int j=;j<=;j++) vis[i*j]=;
  21. int a=read();
  22. if(vis[a]) printf("Yes\n");
  23. else printf("No\n");
  24. return ;
  25. }

B

C - Walk on Multiplication Table

根号枚举一下因数,设因数为 $x$ ,那么看看走到 $(x,n/x)$ 是不是比较短的路径即可

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. typedef long long ll;
  8. inline ll read()
  9. {
  10. ll x=,f=; char ch=getchar();
  11. while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
  12. while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
  13. return x*f;
  14. }
  15. ll n,ans;
  16. int main()
  17. {
  18. n=read(); int t=sqrt(n);
  19. ans=n-;
  20. for(int i=;i<=t;i++)
  21. {
  22. if(n%i) continue;
  23. ans=min(ans,n/i+i-);
  24. }
  25. printf("%lld\n",ans);
  26. return ;
  27. }

C

D - Water Bottle

对我这个数学不好的人来说很不友好啊...

显然二分一下倾斜角看看水是否会倒出来

首先可以把 $x$ 除以 $a$ ,然后就变成平面的问题

然后要特判一下内部是梯形还是三角形就做完了,要注意一下细节,别和我一样把精度设到 $1e-18$ 或者 $-1e18$ ,$\text{2333333}$

放张图比较好理解吧:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. typedef long long ll;
  8. typedef long double ldb;
  9. inline int read()
  10. {
  11. int x=,f=; char ch=getchar();
  12. while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
  13. while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
  14. return x*f;
  15. }
  16. const ldb pi=acos(-1.0),eps=1e-;
  17. ldb a,b,x,ans;
  18. inline bool check(ldb alp)
  19. {
  20. if(a*tan(alp)>=b)
  21. {
  22. ldb y=b/tan(alp);
  23. return y*b/<=x;
  24. }
  25. ldb t=b-a*tan(alp);
  26. return (t+b)*a/<=x;
  27. }
  28. int main()
  29. {
  30. cin>>a>>b>>x;
  31. x/=a;
  32. ldb L=eps,R=pi/-eps;
  33. while(fabsl(R-L)>eps)
  34. {
  35. ldb mid=(L+R)/;
  36. if(check(mid)) R=mid,ans=mid;
  37. else L=mid;
  38. }
  39. printf("%.12Lf\n",ans/pi*);
  40. return ;
  41. }

D

E - Gluttony

首先容易想到最大的 $A$ 和最小的 $F$ 匹配,次大的和次小的匹配...这样匹配下去

然后考虑如何减一些 $A$ ,显然可以二分答案,那么 $check$ 长这样:

  1. inline bool check(ll p)//二分的答案p
  2. {
  3. ll now=K;
  4. for(int i=;i<=n;i++)
  5. {
  6. // af<=p , a<=p/f
  7. if(p/F[i]>=A[i]) continue;
  8. ll t=A[i]-p/F[i];
  9. if(t>now) return ;
  10. now-=t;
  11. }
  12. return ;
  13. }

分析完代码发现,为了最优一定要 $A$ 从小到大对应匹配 $F$ 从大到小,一种证明大概是这样的:

首先可以发现,对于二分的答案 $p$ ,它需要的 $K$ 为 $\sum_{i=1}^{n}max(A_i-\left \lfloor \frac{p}{F_i}\right \rfloor,0)$

那么式子相当于 $\sum_{i=1}^{n}A_i-\sum_{i=1}^{n}\left \lfloor \frac{p}{F_i}\right \rfloor+\sum_{i=1}^{n}[A_i<\left \lfloor \frac{p}{F_i}\right \rfloor](\left \lfloor \frac{p}{F_i}\right \rfloor-A_i)$

发现如果某种匹配能让最后一项求和尽量小,那么即为最优的

然后问题就变成了给长度为 $n$ 的序列 $A,B$ ,求一种匹配使 $\sum_{i=1}^{n}[A_i<B_i](B_i-A_i)$ 最小

首先对于最大的 $B_x$ ,如果 $A_i,A_j$ 都大于 $B_x$ ,那么 $i,j$ 选那个没影响,如果 $A_i<B<A_j$ 显然要让 $A_j$ 去和 $B_x$ 匹配

因为如果让 $A_i$ 和 $B_x$ 匹配,首先产生的代价一定大于 $A_i$ 和 $B_y,y\neq x$ 匹配的代价,然后 $A_j$ 不管和谁匹配代价都为 $0$,那么综合一下还是要让 $A_j$ 去匹配 $B_x$

如果 $A_i<A_j<B$ ,那么如果 $A_i$ 和 $B_x$ 匹配并且 $A_j$ 和 $B_y$ 匹配,如果 $A_j<B_y$ 那么交换 $i,j$ 对答案没影响

但是如果 $A_j>B_y$ ,自己写一下式子会发现代价大于等于 $A_j$ 和 $B_x$ 匹配,$A_i$ 和 $B_y$ 匹配的代价(这里要再分 $B_y$ 和 $A_i$ 之间的关系讨论)

所以综上,$A$ 中最大的和 $B$ 中最大的匹配,次大的和次大的匹配,这样下去一定不会劣于其他方案

回到原来的问题,因为 $F$ 变成了分母,所以要 $F$ 最小的和 $A$ 最大的匹配

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. typedef long long ll;
  8. inline ll read()
  9. {
  10. ll x=,f=; char ch=getchar();
  11. while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
  12. while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
  13. return x*f;
  14. }
  15. const int N=2e5+;
  16. const ll INF=1e12;
  17. ll n,m,A[N],F[N];
  18. inline bool check(ll p)
  19. {
  20. ll now=m;
  21. for(int i=;i<=n;i++)
  22. {
  23. // af<=p , a<=p/f
  24. if(p/F[i]>=A[i]) continue;
  25. ll t=A[i]-p/F[i];
  26. if(t>now) return ;
  27. now-=t;
  28. }
  29. return ;
  30. }
  31. int main()
  32. {
  33. n=read(),m=read();
  34. for(int i=;i<=n;i++) A[i]=read();
  35. for(int i=;i<=n;i++) F[i]=read();
  36. sort(A+,A+n+); sort(F+,F+n+);
  37. reverse(F+,F+n+);
  38. ll L=,R=INF,ans=;
  39. while(L<=R)
  40. {
  41. ll mid=L+R>>;
  42. if(check(mid)) R=mid-,ans=mid;
  43. else L=mid+;
  44. }
  45. printf("%lld\n",ans);
  46. return ;
  47. }

E

F - Fork in the Road

一开始显然会考虑枚举断边然后 $dp$ 一下算代价

设 $f[x]$ 表示从 $x$ 出发最终到达 $n$ 的期望步数,那么转移显然

但是枚举断边复杂度为 $m$,总复杂度为 $m(n+m)$ ,不太行

考虑枚举点,对于某个点 $u$ ,它有若干的出边 $(u,v_i)$

考虑断掉哪条从 $u$ 出发的边是最优的,显然是 $f[v_i]$ 最大的那个,所以只要考虑断最大的那个即可

那么枚举点的复杂度为 $n$ ,总复杂度为 $n(n+m)$,记得如果某个点没法走到 $n$ ,那么期望步数为 $INF$

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<vector>
  7. using namespace std;
  8. typedef long long ll;
  9. typedef double db;
  10. inline int read()
  11. {
  12. int x=,f=; char ch=getchar();
  13. while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
  14. while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
  15. return x*f;
  16. }
  17. const int N=,INF=1e9;
  18. int n,m,a[N*N],b[N*N];
  19. vector <int> V[N];
  20. db f[N],ans;
  21. inline db calc(int p)
  22. {
  23. for(int i=;i<=n;i++) f[i]=;
  24. f[n]=;
  25. for(int i=n-;i>=;i--)
  26. {
  27. int len=V[i].size();
  28. if(p==i&&len==) { f[i]=INF; continue; }
  29. db t=1.0/(len-(p==i)),mx=;
  30. for(int j=;j<len;j++)
  31. {
  32. int v=V[i][j]; mx=max(mx,(f[v]+)*t);
  33. f[i]+=(f[v]+)*t;
  34. }
  35. if(p==i) f[i]-=mx;
  36. }
  37. return f[];
  38. }
  39. int main()
  40. {
  41. n=read(),m=read();
  42. for(int i=;i<=m;i++)
  43. {
  44. a[i]=read(),b[i]=read();
  45. V[a[i]].push_back(b[i]);
  46. }
  47. ans=calc();
  48. for(int i=;i<=n;i++)
  49. ans=min(ans,calc(i));
  50. printf("%.9lf\n",ans);
  51. return ;
  52. }

F

AtCoder Beginner Contest 144 题解的更多相关文章

  1. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  2. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  3. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  4. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  5. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

  6. AtCoder Beginner Contest 172 题解

    AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...

  7. AtCoder Beginner Contest 169 题解

    AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...

  8. AtCoder Beginner Contest 148 题解

    目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...

  9. AtCoder Beginner Contest 151 题解报告

    总的来说,这次的题目比较水,然而菜菜的我并没有把所有题目都做完,话不多说,直接来干货: A:Next Alphabet 题目链接:https://atcoder.jp/contests/abc151/ ...

随机推荐

  1. ios编译库文件时出现的问题

    1. 警告:directory not found for option "xxxxxxxx" 文件路径未找到 选择工程, 编译的 (targets) 选择 Build Setti ...

  2. python将py文件转换为pyc

    python -m py_compile lib/ylpy.py python -m py_compile lib/ylpy.py python 一个.py文件如何调用另一个.py文件中的类和函数 A ...

  3. ArcGIS超级工具SPTOOLS-制图篇

    1.1  梯形接幅表的创建 视频:https://weibo.com/tv/v/Hvq9KzKKQ?fid=1034:4374886702060760 根据一个图层范围,生成接幅表,支持地图比例尺有1 ...

  4. cmder的segmentation fault错误修复

    Segmentation fault 现场还原 问题出现的原因是我在 cmder的命令行里执行了cmder /register ALL命令,本意是把cmder放到右键菜单里去的 但我没想到的是,各种不 ...

  5. c# 线程异步处理

    public class AsyncHelper { private static readonly TaskFactory _myTaskFactory = new TaskFactory(Canc ...

  6. Qt编写安防视频监控系统7-全屏切换

    一.前言 全屏切换这个功能点属于简单的,一般会做到右键菜单中,也提供了快捷键比如alt+enter来触发,恢复全屏则按esc即可,全屏处理基本上都是隐藏通道面板以外的窗体,保持最大化展示,由于采用了模 ...

  7. STM32第二章I/O端口应用

    STM32F10xxx系列中,有7个I/O端口,每个端口有两个32位配置寄存器(GPIOx_CRL,GPIOx_CRH),两个32位数据寄存器(GPIOx_IDR和GPIOx_ODR),一个32位置位 ...

  8. 安装ELectron失败解决方案

    npm安装Electron解决方案 Electron使用npm安装时,因为是国外的镜像源,所以速度会非常慢.而使用cnpm如下命令进行安装时,又会出现安装失败的问题: npm install elec ...

  9. linux下使用openssl和md5sum加密文件或者字符串

    #openssl    //在终端中输入openssl后回车. OpenSSL> md5    //输入md5后回车 123456    //接着输入123456,不要输入回车.然后按3次ctr ...

  10. Shell脚本中怎么实现用户切换实现操作

    当我们在服务器上面疯狂的进行操作的时候,我们用shell脚本来帮我们来完成一些基本的任务,但是一些命令或者一些操作需要我们不断切换用户来实现的话,在shell脚本就不那么好实现了,那么我们在shell ...