版本比较
贪心算法总结
正文
增加 9 行删除 9 行
15 行未改动1617181920202122222324242526262728293031323334353636373839394041424359 行未改动10310410510610710710810911011176 行未改动18818919019119219219319419519653 行未改动250251252253254254255256257258103 行未改动全部展开15 行未改动
此题我们很好想出 贪心 策略:
先取性价比 $(x.v/v.m)$ 高的,再取性价比低的(局部最优)
证明:
如果你选了一个性价比低的,你可以用一个性价比高的等效代替
这种证明叫反证法
代码: ```cpp#include<bits/stdc++.h>using namespace std;struct coin{ int m,v;}a[110];bool operator < (coin x,coin y){ return x.v*y.m<y.v*x.m;} }bool operator > (coin x,coin y){ return x.v*y.m>y.v*x.m;} }void quicksort(int l,int r){ int i=l,j=r; coin flag=a[l+r>>1]; do{59 行未改动# 数学归纳法
例题:[P1080](//www.luogu.org/problemnew/show/P1080)
假设只有两个大臣,为 $1号$ 与 $2号$ 假设只有两个大臣,为 $1号$ 与 $2号$
手上两个数分别是 $(a1,a1)$ , $(a2,b2)$ .
国王手上两数是 $(a0,b0)$76 行未改动 return a[i]; } void fl(int l){ len=l; for(int i=1;i<=len;i++) for(int i=1;i<=len;i++) a[i+1]+=a[i]/10,a[i]%=10; while(!a[len] && len>0) len--; } void print(){53 行未改动例题:[P1803](//www.luogu.org/problemnew/show/P1803)
这道题乍一看挺简单
上 $dfs$ 上 $dfs$
在一看
$1\le n \le 10^{6}$103 行未改动全部展开