防晒
有 头奶牛进行日光浴,第 头奶牛需要 到 单位强度之间的阳光。
每头奶牛在日光浴前必须涂防晒霜,防晒霜有 种,涂上第 种之后,身体接收到的阳光强度就会稳定为 ,第 种防晒霜有 瓶。
求最多可以满足多少头奶牛进行日光浴。
输入格式
第一行输入整数 和 。
接下来的 行,按次序每行输入一头牛的 和 值,即第 行输入 和 。
再接下来的 行,按次序每行输入一种防晒霜的 和 值,即第 行输入 和 。
每行的数据之间用空格隔开。
输出格式
输出一个整数,代表最多可以满足奶牛日光浴的奶牛数目。
数据范围
,
,
输入样例:
3 2
3 10
2 5
1 5
6 2
4 1
输出样例:
2
Point 1观察数据范围,可以接受 级别的方法。尝试对牛按照 排序。那么应该按照什么排序规则呢?
Point 2为了达到最大值,我们需要保证每个防晒霜都用的很有价值,即不能浪费。
我们用 来称呼牛的区间。
- 如果按照从 从小到大排序,那么如果当前我们找到两个防晒霜 满足 可以满足当前牛,思考 对于后面的牛是什么情况?
- 如果按照从 从小到大排序呢? Point 3
- 如果按照 从小到大排序:
- x, y 都不符合
- x 符合,y 不符合
- x 不符合,y 符合
所以,不论我们当前选择 x 还是选择 y,都不能保证最优。
- 如果按照 从小到大排序:
- x 不符合,y 符合
- x,y 都不符合
- x,y 都符合
所以,在这种情况中,我们可以选择 x,把 y 留给后面。因为每个防晒霜只能服务一个牛,所以贪心
的选择 x 是更优的。
所以,按照右端点从小到大排序,右端点相同则按照左端点从小到大排序。
依次遍历每头奶牛,去寻找所有满足该牛要求的防晒霜中SPF值最小的哪一个。
#include <bits/stdc++.h>
using namespace std;
struct node{
int mi;
int mx;
}a[3000];
int C,L;
struct SPF{
int num;
int spf;
}s[3000];
bool cmp(node a,node b){
if(a.mx==b.mx)
return a.mi<b.mi;
return a.mx<b.mx;
}
bool cmp2(SPF a,SPF b){
return a.spf<b.spf;
}
int main(){
scanf("%d%d",&C,&L);
for(int i=0;i<C;i++)
scanf("%d%d",&a[i].mi,&a[i].mx);
for(int i=0;i<L;i++)
scanf("%d%d",&s[i].spf,&s[i].num);
sort(a,a+C,cmp);
sort(s,s+L,cmp2);
int ans = 0;
for(int i=0;i<C;i++){
for(int j=0;j<L;j++){
if(s[j].spf>=a[i].mi&&s[j].spf<=a[i].mx&&s[j].num>0){
s[j].num--;
ans++;
break;
}
}
}
cout<<ans<<endl;
return 0;
}
畜栏预定
有 头牛在畜栏中吃草。
每个畜栏在同一时间段只能提供给一头牛吃草,所以可能会需要多个畜栏。
给定 头牛和每头牛开始吃草的时间 以及结束吃草的时间 ,每头牛在 这一时间段内都会一直吃草。
当两头牛的吃草区间存在交集时(包括端点),这两头牛不能被安排在同一个畜栏吃草。
求需要的最小畜栏数目和每头牛对应的畜栏方案。
输入格式
第 行:输入一个整数 。
第 行:第 行输入第 头牛的开始吃草时间 以及结束吃草时间 ,数之间用空格隔开。
输出格式
第 行:输入一个整数,代表所需最小畜栏数。
第 行:第 行输入第 头牛被安排到的畜栏编号,编号是从 开始的 连续 整数,只要方案合法即可。
数据范围
,
输入样例:
5
1 10
2 4
3 6
5 8
4 7
输出样例:
4
1
2
3
2
4
将区间按照左端点从小到大排序,左端点相同则按照右端点排序。
用优先队列维护当前每个蓄栏结束使用的时间,对于每个区间,若最小结束使用的蓄栏可供当前区间使用,则修改后继续放入优先队列,否则直接在优先队列中添加一个新的元素。
#include<bits/stdc++.h>
using namespace std;
#define dbg(x...) do { cout << "\033[32;1m" << #x <<" -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<class T, class... Ts> void err(const T& arg,const Ts&... args) { cout << arg << " "; err(args...); }
#define rep(i,j,k) for(int i=int(j);i<=int(k);i++)
#define per(i,j,k) for(int i=int(j);i>=int(k);i--)
typedef long long ll;
const int N = 50005;
using PII = pair<int, int>;
int n, b[N];
struct Cow {
int l, r, id;
bool operator < (const Cow & rth)const {
return l < rth.l;
}
};
Cow a[N];
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i].l >> a[i].r;
a[i].id = i;
}
sort(a + 1, a + n + 1);
priority_queue<PII, vector<PII>, greater<PII>> q;
for(int i = 1; i <= n; i++) {
int l = a[i].l, r = a[i].r, id = a[i].id;
if(q.size() == 0 || q.top().first > l) {
b[id] = q.size() + 1;
q.push({r + 1, b[id]});
} else {
b[id] = q.top().second; q.pop();
q.push({r + 1, b[id]});
}
}
cout << q.size() << "\n";
for(int i = 1; i <= n; i++) {
cout << b[i] << "\n";
}
return 0;
}
雷达设备
假设海岸是一条无限长的直线,陆地位于海岸的一侧,海洋位于另外一侧。
每个小岛都位于海洋一侧的某个点上。
雷达装置均位于海岸线上,且雷达的监测范围为 ,当小岛与某雷达的距离不超过 时,该小岛可以被雷达覆盖。
我们使用笛卡尔坐标系,定义海岸线为 轴,海的一侧在 轴上方,陆地一侧在 轴下方。
现在给出每个小岛的具体坐标以及雷达的检测范围,请你求出能够使所有小岛都被雷达覆盖所需的最小雷达数目。
输入格式
第一行输入两个整数 和 ,分别代表小岛数目和雷达检测范围。
接下来 行,每行输入两个整数,分别代表小岛的 轴坐标。
同一行数据之间用空格隔开。
输出格式
输出一个整数,代表所需的最小雷达数目,若没有解决方案则所需数目输出 。
数据范围
,
输入样例:
3 2
1 2
-3 1
2 1
输出样例:
2
一个小岛要想被一个雷达覆盖,根据勾股定理,可以计算雷达的可行区间 [l, r] ,然后问题转换为若干个区间,问最少有多少个点可以将所有区间覆盖。
对区间按照左端点排序,然后从左到右依次考虑。尽可能的将雷达往右放置。
#include <bits/stdc++.h>
using namespace std;
struct node{
double l,r;
}a[1010];
int n;
double d;
bool cmp(node a,node b){
if(a.l==b.l)return a.r<b.r;
return a.l<b.l;
}
int main(){
scanf("%d%lf",&n,&d);
bool flag = false;
for(int i=0;i<n;i++){
double x,y;
scanf("%lf%lf",&x,&y);
if(y>d)flag = true;
a[i].l = x-sqrt(d*d-y*y);
a[i].r = 2*x-a[i].l;
}
if(flag){
cout<<-1<<endl;
return 0;
}
sort(a,a+n,cmp);
int num = 1;
double left = a[0].r;
for(int i=1;i<n;i++)
if(left>=a[i].l)
left = min(left,a[i].r);
else{
left = a[i].r;
num++;
}
cout<<num<<endl;
return 0;
}
国王游戏
恰逢 国国庆,国王邀请 位大臣来玩一个有奖游戏。
首先,他让每个大臣在左、右手上面分别写下一个整数,国王自己也在左、右手上各写一个整数。
然后,让这 位大臣排成一排,国王站在队伍的最前面。
排好队后,所有的大臣都会获得国王奖赏的若干金币,每位大臣获得的金币数分别是:
排在该大臣前面的所有人的左手上的数的乘积除以他自己右手上的数,然后向下取整得到的结果。
国王不希望某一个大臣获得特别多的奖赏,所以他想请你帮他重新安排一下队伍的顺序,使得获得奖赏最多的大臣,所获奖赏尽可能的少。
注意,国王的位置始终在队伍的最前面。
输入格式
第一行包含一个整数 ,表示大臣的人数。
第二行包含两个整数 和 ,之间用一个空格隔开,分别表示国王左手和右手上的整数。
接下来 行,每行包含两个整数 和 ,之间用一个空格隔开,分别表示每个大臣左手和右手上的整数。
输出格式
输出只有一行,包含一个整数,表示重新排列后的队伍中获奖赏最多的大臣所获得的金币数。
数据范围
输入样例:
3
1 1
2 3
7 4
4 6
输出样例:
2
每个大臣获得的金币是前面所有人左手数量的乘积除以自己右手的乘积。
设前 i - 1 个人左手乘积为 mul,我们来考虑第 i 个人与第 i + 1 个人的获得金币的情况。
,如果第 i 个人与第 i + 1 个人交换,则变为。
所以,如果前者大于后者,那么这次交换将会使得答案变得更小:
%20%26gt%3B%20max(mul%20%2F%20r%7Bi%2B1%7D%2C%20mul%20*%20l%7Bi%2B1%7D%20%2F%20ri)%3C%2Ftitle%3E%0A%3Cdefs%20aria-hidden%3D%22true%22%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-6D%22%20d%3D%22M21%20287Q22%20293%2024%20303T36%20341T56%20388T88%20425T132%20442T175%20435T205%20417T221%20395T229%20376L231%20369Q231%20367%20232%20367L243%20378Q303%20442%20384%20442Q401%20442%20415%20440T441%20433T460%20423T475%20411T485%20398T493%20385T497%20373T500%20364T502%20357L510%20367Q573%20442%20659%20442Q713%20442%20746%20415T780%20336Q780%20285%20742%20178T704%2050Q705%2036%20709%2031T724%2026Q752%2026%20776%2056T815%20138Q818%20149%20821%20151T837%20153Q857%20153%20857%20145Q857%20144%20853%20130Q845%20101%20831%2073T785%2017T716%20-10Q669%20-10%20648%2017T627%2073Q627%2092%20663%20193T700%20345Q700%20404%20656%20404H651Q565%20404%20506%20303L499%20291L466%20157Q433%2026%20428%2016Q415%20-11%20385%20-11Q372%20-11%20364%20-4T353%208T350%2018Q350%2029%20384%20161L420%20307Q423%20322%20423%20345Q423%20404%20379%20404H374Q288%20404%20229%20303L222%20291L189%20157Q156%2026%20151%2016Q138%20-11%20108%20-11Q95%20-11%2087%20-5T76%207T74%2017Q74%2030%20112%20181Q151%20335%20151%20342Q154%20357%20154%20369Q154%20405%20129%20405Q107%20405%2092%20377T69%20316T57%20280Q55%20278%2041%20278H27Q21%20284%2021%20287Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-61%22%20d%3D%22M33%20157Q33%20258%20109%20349T280%20441Q331%20441%20370%20392Q386%20422%20416%20422Q429%20422%20439%20414T449%20394Q449%20381%20412%20234T374%2068Q374%2043%20381%2035T402%2026Q411%2027%20422%2035Q443%2055%20463%20131Q469%20151%20473%20152Q475%20153%20483%20153H487Q506%20153%20506%20144Q506%20138%20501%20117T481%2063T449%2013Q436%200%20417%20-8Q409%20-10%20393%20-10Q359%20-10%20336%205T306%2036L300%2051Q299%2052%20296%2050Q294%2048%20292%2046Q233%20-10%20172%20-10Q117%20-10%2075%2030T33%20157ZM351%20328Q351%20334%20346%20350T323%20385T277%20405Q242%20405%20210%20374T160%20293Q131%20214%20119%20129Q119%20126%20119%20118T118%20106Q118%2061%20136%2044T179%2026Q217%2026%20254%2059T298%20110Q300%20114%20325%20217T351%20328Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-78%22%20d%3D%22M52%20289Q59%20331%20106%20386T222%20442Q257%20442%20286%20424T329%20379Q371%20442%20430%20442Q467%20442%20494%20420T522%20361Q522%20332%20508%20314T481%20292T458%20288Q439%20288%20427%20299T415%20328Q415%20374%20465%20391Q454%20404%20425%20404Q412%20404%20406%20402Q368%20386%20350%20336Q290%20115%20290%2078Q290%2050%20306%2038T341%2026Q378%2026%20414%2059T463%20140Q466%20150%20469%20151T485%20153H489Q504%20153%20504%20145Q504%20144%20502%20134Q486%2077%20440%2033T333%20-11Q263%20-11%20227%2052Q186%20-10%20133%20-10H127Q78%20-10%2057%2016T35%2071Q35%20103%2054%20123T99%20143Q142%20143%20142%20101Q142%2081%20130%2066T107%2046T94%2041L91%2040Q91%2039%2097%2036T113%2029T132%2026Q168%2026%20194%2071Q203%2087%20217%20139T245%20247T261%20313Q266%20340%20266%20352Q266%20380%20251%20392T217%20404Q177%20404%20142%20372T93%20290Q91%20281%2088%20280T72%20278H58Q52%20284%2052%20289Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-28%22%20d%3D%22M94%20250Q94%20319%20104%20381T127%20488T164%20576T202%20643T244%20695T277%20729T302%20750H315H319Q333%20750%20333%20741Q333%20738%20316%20720T275%20667T226%20581T184%20443T167%20250T184%2058T225%20-81T274%20-167T316%20-220T333%20-241Q333%20-250%20318%20-250H315H302L274%20-226Q180%20-141%20137%20-14T94%20250Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-75%22%20d%3D%22M21%20287Q21%20295%2030%20318T55%20370T99%20420T158%20442Q204%20442%20227%20417T250%20358Q250%20340%20216%20246T182%20105Q182%2062%20196%2045T238%2027T291%2044T328%2078L339%2095Q341%2099%20377%20247Q407%20367%20413%20387T427%20416Q444%20431%20463%20431Q480%20431%20488%20421T496%20402L420%2084Q419%2079%20419%2068Q419%2043%20426%2035T447%2026Q469%2029%20482%2057T512%20145Q514%20153%20532%20153Q551%20153%20551%20144Q550%20139%20549%20130T540%2098T523%2055T498%2017T462%20-8Q454%20-10%20438%20-10Q372%20-10%20347%2046Q345%2045%20336%2036T318%2021T296%206T267%20-6T233%20-11Q189%20-11%20155%207Q103%2038%20103%20113Q103%20170%20138%20262T173%20379Q173%20380%20173%20381Q173%20390%20173%20393T169%20400T158%20404H154Q131%20404%20112%20385T82%20344T65%20302T57%20280Q55%20278%2041%20278H27Q21%20284%2021%20287Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-6C%22%20d%3D%22M117%2059Q117%2026%20142%2026Q179%2026%20205%20131Q211%20151%20215%20152Q217%20153%20225%20153H229Q238%20153%20241%20153T246%20151T248%20144Q247%20138%20245%20128T234%2090T214%2043T183%206T137%20-11Q101%20-11%2070%2011T38%2085Q38%2097%2039%20102L104%20360Q167%20615%20167%20623Q167%20626%20166%20628T162%20632T157%20634T149%20635T141%20636T132%20637T122%20637Q112%20637%20109%20637T101%20638T95%20641T94%20647Q94%20649%2096%20661Q101%20680%20107%20682T179%20688Q194%20689%20213%20690T243%20693T254%20694Q266%20694%20266%20686Q266%20675%20193%20386T118%2083Q118%2081%20118%2075T117%2065V59Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-2F%22%20d%3D%22M423%20750Q432%20750%20438%20744T444%20730Q444%20725%20271%20248T92%20-240Q85%20-250%2075%20-250Q68%20-250%2062%20-245T56%20-231Q56%20-221%20230%20257T407%20740Q411%20750%20423%20750Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-72%22%20d%3D%22M21%20287Q22%20290%2023%20295T28%20317T38%20348T53%20381T73%20411T99%20433T132%20442Q161%20442%20183%20430T214%20408T225%20388Q227%20382%20228%20382T236%20389Q284%20441%20347%20441H350Q398%20441%20422%20400Q430%20381%20430%20363Q430%20333%20417%20315T391%20292T366%20288Q346%20288%20334%20299T322%20328Q322%20376%20378%20392Q356%20405%20342%20405Q286%20405%20239%20331Q229%20315%20224%20298T190%20165Q156%2025%20151%2016Q138%20-11%20108%20-11Q95%20-11%2087%20-5T76%207T74%2017Q74%2030%20114%20189T154%20366Q154%20405%20128%20405Q107%20405%2092%20377T68%20316T57%20280Q55%20278%2041%20278H27Q21%20284%2021%20287Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-69%22%20d%3D%22M184%20600Q184%20624%20203%20642T247%20661Q265%20661%20277%20649T290%20619Q290%20596%20270%20577T226%20557Q211%20557%20198%20567T184%20600ZM21%20287Q21%20295%2030%20318T54%20369T98%20420T158%20442Q197%20442%20223%20419T250%20357Q250%20340%20236%20301T196%20196T154%2083Q149%2061%20149%2051Q149%2026%20166%2026Q175%2026%20185%2029T208%2043T235%2078T260%20137Q263%20149%20265%20151T282%20153Q302%20153%20302%20143Q302%20135%20293%20112T268%2061T223%2011T161%20-11Q129%20-11%20102%2010T74%2074Q74%2091%2079%20106T122%20220Q160%20321%20166%20341T173%20380Q173%20404%20156%20404H154Q124%20404%2099%20371T61%20287Q60%20286%2059%20284T58%20281T56%20279T53%20278T49%20278T41%20278H27Q21%20284%2021%20287Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-2C%22%20d%3D%22M78%2035T78%2060T94%20103T137%20121Q165%20121%20187%2096T210%208Q210%20-27%20201%20-60T180%20-117T154%20-158T130%20-185T117%20-194Q113%20-194%20104%20-185T95%20-172Q95%20-168%20106%20-156T131%20-126T157%20-76T173%20-3V9L172%208Q170%207%20167%206T161%203T152%201T140%200Q113%200%2096%2017Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-2217%22%20d%3D%22M229%20286Q216%20420%20216%20436Q216%20454%20240%20464Q241%20464%20245%20464T251%20465Q263%20464%20273%20456T283%20436Q283%20419%20277%20356T270%20286L328%20328Q384%20369%20389%20372T399%20375Q412%20375%20423%20365T435%20338Q435%20325%20425%20315Q420%20312%20357%20282T289%20250L355%20219L425%20184Q434%20175%20434%20161Q434%20146%20425%20136T401%20125Q393%20125%20383%20131T328%20171L270%20213Q283%2079%20283%2063Q283%2053%20276%2044T250%2035Q231%2035%20224%2044T216%2063Q216%2080%20222%20143T229%20213L171%20171Q115%20130%20110%20127Q106%20124%20100%20124Q87%20124%2076%20134T64%20161Q64%20166%2064%20169T67%20175T72%20181T81%20188T94%20195T113%20204T138%20215T170%20230T210%20250L74%20315Q65%20324%2065%20338Q65%20353%2074%20363T98%20374Q106%20374%20116%20368T171%20328L229%20286Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-2B%22%20d%3D%22M56%20237T56%20250T70%20270H369V420L370%20570Q380%20583%20389%20583Q402%20583%20409%20568V270H707Q722%20262%20722%20250T707%20230H409V-68Q401%20-82%20391%20-82H389H387Q375%20-82%20369%20-68V230H70Q56%20237%2056%20250Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-31%22%20d%3D%22M213%20578L200%20573Q186%20568%20160%20563T102%20556H83V602H102Q149%20604%20189%20617T245%20641T273%20663Q275%20666%20285%20666Q294%20666%20302%20660V361L303%2061Q310%2054%20315%2052T339%2048T401%2046H427V0H416Q395%203%20257%203Q121%203%20100%200H88V46H114Q136%2046%20152%2046T177%2047T193%2050T201%2052T207%2057T213%2061V578Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-29%22%20d%3D%22M60%20749L64%20750Q69%20750%2074%20750H86L114%20726Q208%20641%20251%20514T294%20250Q294%20182%20284%20119T261%2012T224%20-76T186%20-143T145%20-194T113%20-227T90%20-246Q87%20-249%2086%20-250H74Q66%20-250%2063%20-250T58%20-247T55%20-238Q56%20-237%2066%20-225Q221%20-64%20221%20250T66%20725Q56%20737%2055%20738Q55%20746%2060%20749Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-3E%22%20d%3D%22M84%20520Q84%20528%2088%20533T96%20539L99%20540Q106%20540%20253%20471T544%20334L687%20265Q694%20260%20694%20250T687%20235Q685%20233%20395%2096L107%20-40H101Q83%20-38%2083%20-20Q83%20-19%2083%20-17Q82%20-10%2098%20-1Q117%209%20248%2071Q326%20108%20378%20132L626%20250L378%20368Q90%20504%2086%20509Q84%20513%2084%20520Z%22%3E%3C%2Fpath%3E%0A%3C%2Fdefs%3E%0A%3Cg%20stroke%3D%22currentColor%22%20fill%3D%22currentColor%22%20stroke-width%3D%220%22%20transform%3D%22matrix(1%200%200%20-1%200%200)%22%20aria-hidden%3D%22true%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6D%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-61%22%20x%3D%22878%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-78%22%20x%3D%221408%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-28%22%20x%3D%221980%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6D%22%20x%3D%222370%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-75%22%20x%3D%223248%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6C%22%20x%3D%223821%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-2F%22%20x%3D%224119%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(4620%2C0)%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-72%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMATHI-69%22%20x%3D%22638%22%20y%3D%22-213%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-2C%22%20x%3D%225415%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6D%22%20x%3D%225860%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-75%22%20x%3D%226739%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6C%22%20x%3D%227311%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-2217%22%20x%3D%227832%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(8555%2C0)%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6C%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMATHI-69%22%20x%3D%22422%22%20y%3D%22-213%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-2F%22%20x%3D%229198%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(9698%2C0)%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-72%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(451%2C-150)%22%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMATHI-69%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMAIN-2B%22%20x%3D%22345%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMAIN-31%22%20x%3D%221124%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%3C%2Fg%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-29%22%20x%3D%2211398%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-3E%22%20x%3D%2212066%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6D%22%20x%3D%2213122%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-61%22%20x%3D%2214000%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-78%22%20x%3D%2214530%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-28%22%20x%3D%2215102%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6D%22%20x%3D%2215492%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-75%22%20x%3D%2216370%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6C%22%20x%3D%2216943%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-2F%22%20x%3D%2217241%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(17742%2C0)%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-72%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(451%2C-150)%22%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMATHI-69%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMAIN-2B%22%20x%3D%22345%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMAIN-31%22%20x%3D%221124%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%3C%2Fg%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-2C%22%20x%3D%2219442%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6D%22%20x%3D%2219887%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-75%22%20x%3D%2220766%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6C%22%20x%3D%2221338%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-2217%22%20x%3D%2221859%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(22582%2C0)%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6C%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(298%2C-150)%22%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMATHI-69%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMAIN-2B%22%20x%3D%22345%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMAIN-31%22%20x%3D%221124%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%3C%2Fg%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-2F%22%20x%3D%2224129%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(24629%2C0)%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-72%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMATHI-69%22%20x%3D%22638%22%20y%3D%22-213%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-29%22%20x%3D%2225425%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%3C%2Fsvg%3E#card=math&code=max%28mul%20%2F%20r_i%2C%20mul%20%2A%20l_i%20%2F%20r%7Bi%2B1%7D%29%20%3E%20max%28mul%20%2F%20r%7Bi%2B1%7D%2C%20mul%20%2A%20l%7Bi%2B1%7D%20%2F%20ri%29%0A&id=VK5Uw)
整体通分,即:
![](data:image/svg+xml;utf8,%3Csvg%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20width%3D%2239.055ex%22%20height%3D%222.843ex%22%20style%3D%22vertical-align%3A%20-0.838ex%3B%22%20viewBox%3D%220%20-863.1%2016815.3%201223.9%22%20role%3D%22img%22%20focusable%3D%22false%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20aria-labelledby%3D%22MathJax-SVG-1-Title%22%3E%0A%3Ctitle%20id%3D%22MathJax-SVG-1-Title%22%3Emax(r%7Bi%2B1%7D%2C%20li*r_i)%20%26gt%3B%20max(r%7Bi%7D%2C%20l%7Bi%2B1%7D*r%7Bi%2B1%7D)%3C%2Ftitle%3E%0A%3Cdefs%20aria-hidden%3D%22true%22%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-6D%22%20d%3D%22M21%20287Q22%20293%2024%20303T36%20341T56%20388T88%20425T132%20442T175%20435T205%20417T221%20395T229%20376L231%20369Q231%20367%20232%20367L243%20378Q303%20442%20384%20442Q401%20442%20415%20440T441%20433T460%20423T475%20411T485%20398T493%20385T497%20373T500%20364T502%20357L510%20367Q573%20442%20659%20442Q713%20442%20746%20415T780%20336Q780%20285%20742%20178T704%2050Q705%2036%20709%2031T724%2026Q752%2026%20776%2056T815%20138Q818%20149%20821%20151T837%20153Q857%20153%20857%20145Q857%20144%20853%20130Q845%20101%20831%2073T785%2017T716%20-10Q669%20-10%20648%2017T627%2073Q627%2092%20663%20193T700%20345Q700%20404%20656%20404H651Q565%20404%20506%20303L499%20291L466%20157Q433%2026%20428%2016Q415%20-11%20385%20-11Q372%20-11%20364%20-4T353%208T350%2018Q350%2029%20384%20161L420%20307Q423%20322%20423%20345Q423%20404%20379%20404H374Q288%20404%20229%20303L222%20291L189%20157Q156%2026%20151%2016Q138%20-11%20108%20-11Q95%20-11%2087%20-5T76%207T74%2017Q74%2030%20112%20181Q151%20335%20151%20342Q154%20357%20154%20369Q154%20405%20129%20405Q107%20405%2092%20377T69%20316T57%20280Q55%20278%2041%20278H27Q21%20284%2021%20287Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-61%22%20d%3D%22M33%20157Q33%20258%20109%20349T280%20441Q331%20441%20370%20392Q386%20422%20416%20422Q429%20422%20439%20414T449%20394Q449%20381%20412%20234T374%2068Q374%2043%20381%2035T402%2026Q411%2027%20422%2035Q443%2055%20463%20131Q469%20151%20473%20152Q475%20153%20483%20153H487Q506%20153%20506%20144Q506%20138%20501%20117T481%2063T449%2013Q436%200%20417%20-8Q409%20-10%20393%20-10Q359%20-10%20336%205T306%2036L300%2051Q299%2052%20296%2050Q294%2048%20292%2046Q233%20-10%20172%20-10Q117%20-10%2075%2030T33%20157ZM351%20328Q351%20334%20346%20350T323%20385T277%20405Q242%20405%20210%20374T160%20293Q131%20214%20119%20129Q119%20126%20119%20118T118%20106Q118%2061%20136%2044T179%2026Q217%2026%20254%2059T298%20110Q300%20114%20325%20217T351%20328Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-78%22%20d%3D%22M52%20289Q59%20331%20106%20386T222%20442Q257%20442%20286%20424T329%20379Q371%20442%20430%20442Q467%20442%20494%20420T522%20361Q522%20332%20508%20314T481%20292T458%20288Q439%20288%20427%20299T415%20328Q415%20374%20465%20391Q454%20404%20425%20404Q412%20404%20406%20402Q368%20386%20350%20336Q290%20115%20290%2078Q290%2050%20306%2038T341%2026Q378%2026%20414%2059T463%20140Q466%20150%20469%20151T485%20153H489Q504%20153%20504%20145Q504%20144%20502%20134Q486%2077%20440%2033T333%20-11Q263%20-11%20227%2052Q186%20-10%20133%20-10H127Q78%20-10%2057%2016T35%2071Q35%20103%2054%20123T99%20143Q142%20143%20142%20101Q142%2081%20130%2066T107%2046T94%2041L91%2040Q91%2039%2097%2036T113%2029T132%2026Q168%2026%20194%2071Q203%2087%20217%20139T245%20247T261%20313Q266%20340%20266%20352Q266%20380%20251%20392T217%20404Q177%20404%20142%20372T93%20290Q91%20281%2088%20280T72%20278H58Q52%20284%2052%20289Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-28%22%20d%3D%22M94%20250Q94%20319%20104%20381T127%20488T164%20576T202%20643T244%20695T277%20729T302%20750H315H319Q333%20750%20333%20741Q333%20738%20316%20720T275%20667T226%20581T184%20443T167%20250T184%2058T225%20-81T274%20-167T316%20-220T333%20-241Q333%20-250%20318%20-250H315H302L274%20-226Q180%20-141%20137%20-14T94%20250Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-72%22%20d%3D%22M21%20287Q22%20290%2023%20295T28%20317T38%20348T53%20381T73%20411T99%20433T132%20442Q161%20442%20183%20430T214%20408T225%20388Q227%20382%20228%20382T236%20389Q284%20441%20347%20441H350Q398%20441%20422%20400Q430%20381%20430%20363Q430%20333%20417%20315T391%20292T366%20288Q346%20288%20334%20299T322%20328Q322%20376%20378%20392Q356%20405%20342%20405Q286%20405%20239%20331Q229%20315%20224%20298T190%20165Q156%2025%20151%2016Q138%20-11%20108%20-11Q95%20-11%2087%20-5T76%207T74%2017Q74%2030%20114%20189T154%20366Q154%20405%20128%20405Q107%20405%2092%20377T68%20316T57%20280Q55%20278%2041%20278H27Q21%20284%2021%20287Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-69%22%20d%3D%22M184%20600Q184%20624%20203%20642T247%20661Q265%20661%20277%20649T290%20619Q290%20596%20270%20577T226%20557Q211%20557%20198%20567T184%20600ZM21%20287Q21%20295%2030%20318T54%20369T98%20420T158%20442Q197%20442%20223%20419T250%20357Q250%20340%20236%20301T196%20196T154%2083Q149%2061%20149%2051Q149%2026%20166%2026Q175%2026%20185%2029T208%2043T235%2078T260%20137Q263%20149%20265%20151T282%20153Q302%20153%20302%20143Q302%20135%20293%20112T268%2061T223%2011T161%20-11Q129%20-11%20102%2010T74%2074Q74%2091%2079%20106T122%20220Q160%20321%20166%20341T173%20380Q173%20404%20156%20404H154Q124%20404%2099%20371T61%20287Q60%20286%2059%20284T58%20281T56%20279T53%20278T49%20278T41%20278H27Q21%20284%2021%20287Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-2B%22%20d%3D%22M56%20237T56%20250T70%20270H369V420L370%20570Q380%20583%20389%20583Q402%20583%20409%20568V270H707Q722%20262%20722%20250T707%20230H409V-68Q401%20-82%20391%20-82H389H387Q375%20-82%20369%20-68V230H70Q56%20237%2056%20250Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-31%22%20d%3D%22M213%20578L200%20573Q186%20568%20160%20563T102%20556H83V602H102Q149%20604%20189%20617T245%20641T273%20663Q275%20666%20285%20666Q294%20666%20302%20660V361L303%2061Q310%2054%20315%2052T339%2048T401%2046H427V0H416Q395%203%20257%203Q121%203%20100%200H88V46H114Q136%2046%20152%2046T177%2047T193%2050T201%2052T207%2057T213%2061V578Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-2C%22%20d%3D%22M78%2035T78%2060T94%20103T137%20121Q165%20121%20187%2096T210%208Q210%20-27%20201%20-60T180%20-117T154%20-158T130%20-185T117%20-194Q113%20-194%20104%20-185T95%20-172Q95%20-168%20106%20-156T131%20-126T157%20-76T173%20-3V9L172%208Q170%207%20167%206T161%203T152%201T140%200Q113%200%2096%2017Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMATHI-6C%22%20d%3D%22M117%2059Q117%2026%20142%2026Q179%2026%20205%20131Q211%20151%20215%20152Q217%20153%20225%20153H229Q238%20153%20241%20153T246%20151T248%20144Q247%20138%20245%20128T234%2090T214%2043T183%206T137%20-11Q101%20-11%2070%2011T38%2085Q38%2097%2039%20102L104%20360Q167%20615%20167%20623Q167%20626%20166%20628T162%20632T157%20634T149%20635T141%20636T132%20637T122%20637Q112%20637%20109%20637T101%20638T95%20641T94%20647Q94%20649%2096%20661Q101%20680%20107%20682T179%20688Q194%20689%20213%20690T243%20693T254%20694Q266%20694%20266%20686Q266%20675%20193%20386T118%2083Q118%2081%20118%2075T117%2065V59Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-2217%22%20d%3D%22M229%20286Q216%20420%20216%20436Q216%20454%20240%20464Q241%20464%20245%20464T251%20465Q263%20464%20273%20456T283%20436Q283%20419%20277%20356T270%20286L328%20328Q384%20369%20389%20372T399%20375Q412%20375%20423%20365T435%20338Q435%20325%20425%20315Q420%20312%20357%20282T289%20250L355%20219L425%20184Q434%20175%20434%20161Q434%20146%20425%20136T401%20125Q393%20125%20383%20131T328%20171L270%20213Q283%2079%20283%2063Q283%2053%20276%2044T250%2035Q231%2035%20224%2044T216%2063Q216%2080%20222%20143T229%20213L171%20171Q115%20130%20110%20127Q106%20124%20100%20124Q87%20124%2076%20134T64%20161Q64%20166%2064%20169T67%20175T72%20181T81%20188T94%20195T113%20204T138%20215T170%20230T210%20250L74%20315Q65%20324%2065%20338Q65%20353%2074%20363T98%20374Q106%20374%20116%20368T171%20328L229%20286Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-29%22%20d%3D%22M60%20749L64%20750Q69%20750%2074%20750H86L114%20726Q208%20641%20251%20514T294%20250Q294%20182%20284%20119T261%2012T224%20-76T186%20-143T145%20-194T113%20-227T90%20-246Q87%20-249%2086%20-250H74Q66%20-250%2063%20-250T58%20-247T55%20-238Q56%20-237%2066%20-225Q221%20-64%20221%20250T66%20725Q56%20737%2055%20738Q55%20746%2060%20749Z%22%3E%3C%2Fpath%3E%0A%3Cpath%20stroke-width%3D%221%22%20id%3D%22E1-MJMAIN-3E%22%20d%3D%22M84%20520Q84%20528%2088%20533T96%20539L99%20540Q106%20540%20253%20471T544%20334L687%20265Q694%20260%20694%20250T687%20235Q685%20233%20395%2096L107%20-40H101Q83%20-38%2083%20-20Q83%20-19%2083%20-17Q82%20-10%2098%20-1Q117%209%20248%2071Q326%20108%20378%20132L626%20250L378%20368Q90%20504%2086%20509Q84%20513%2084%20520Z%22%3E%3C%2Fpath%3E%0A%3C%2Fdefs%3E%0A%3Cg%20stroke%3D%22currentColor%22%20fill%3D%22currentColor%22%20stroke-width%3D%220%22%20transform%3D%22matrix(1%200%200%20-1%200%200)%22%20aria-hidden%3D%22true%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6D%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-61%22%20x%3D%22878%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-78%22%20x%3D%221408%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-28%22%20x%3D%221980%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(2370%2C0)%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-72%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(451%2C-150)%22%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMATHI-69%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMAIN-2B%22%20x%3D%22345%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMAIN-31%22%20x%3D%221124%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%3C%2Fg%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-2C%22%20x%3D%224070%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(4515%2C0)%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6C%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMATHI-69%22%20x%3D%22422%22%20y%3D%22-213%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-2217%22%20x%3D%225380%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(6103%2C0)%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-72%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMATHI-69%22%20x%3D%22638%22%20y%3D%22-213%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-29%22%20x%3D%226898%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-3E%22%20x%3D%227566%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6D%22%20x%3D%228622%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-61%22%20x%3D%229500%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-78%22%20x%3D%2210030%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-28%22%20x%3D%2210602%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(10992%2C0)%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-72%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMATHI-69%22%20x%3D%22638%22%20y%3D%22-213%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-2C%22%20x%3D%2211788%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(12233%2C0)%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-6C%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(298%2C-150)%22%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMATHI-69%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMAIN-2B%22%20x%3D%22345%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMAIN-31%22%20x%3D%221124%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%3C%2Fg%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-2217%22%20x%3D%2214002%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(14725%2C0)%22%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMATHI-72%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3Cg%20transform%3D%22translate(451%2C-150)%22%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMATHI-69%22%20x%3D%220%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMAIN-2B%22%20x%3D%22345%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%20%3Cuse%20transform%3D%22scale(0.707)%22%20xlink%3Ahref%3D%22%23E1-MJMAIN-31%22%20x%3D%221124%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%3C%2Fg%3E%0A%20%3Cuse%20xlink%3Ahref%3D%22%23E1-MJMAIN-29%22%20x%3D%2216425%22%20y%3D%220%22%3E%3C%2Fuse%3E%0A%3C%2Fg%3E%0A%3C%2Fsvg%3E#card=math&code=max%28r%7Bi%2B1%7D%2C%20l_i%2Ar_i%29%20%3E%20max%28r%7Bi%7D%2C%20l%7Bi%2B1%7D%2Ar%7Bi%2B1%7D%29%0A&id=sVtTN)
可以进一步化简:
当上述条件发生时,应当置换顺序,所以,要按照 l * r 升序排列。
另外这个题目计算结果没有取模,所以需要用高精度乘法和除法。
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=int(j);i<=int(k);i++)
#define per(i,j,k) for(int i=int(j);i>=int(k);i--)
typedef long long ll;
const int N = 100010;
int n;
pair<int,int> a[N];
class Int {
public:
Int(long long num = 0) { *this = num; }
Int(string str) { *this = str; }
Int(const Int& o) { this->s = o.s; }
Int(const vector<int> & o) { this->s = o; }
Int operator = (long long num) { transform(s, abs(num)); return *this; }
Int operator = (string &str) {
s.clear();
int x = 0, len = (str.length() + WIDTH - 1) / WIDTH;
for(int i = 0; i < len; i++){
int ed = str.length() - i * WIDTH;
int st = max(0, ed - WIDTH);
sscanf(str.substr(st, ed - st).c_str(), "%d", &x);
s.push_back(x);
}
adjust(s);
return *this;
}
bool operator < (Int &o) { return compare(s, o.s); }
bool operator > (Int &o) { return o < *this; }
bool operator <= (Int &o) { return !(o < *this); }
bool operator >= (Int &o) { return !(*this < o); }
bool operator == (Int &o) { return !(o < *this) && (*this < o); }
Int operator + (Int &o) { return Int(add(s, o.s)); };
Int operator - (Int &o) { return Int(sub(s, o.s)); };
Int operator * (Int &o) { return Int(mul(s, o.s)); };
Int operator * (int &o) { return Int(mul(s, o)); };
Int operator / (Int &o) { return *this < o ? 0 : Int(div(s, o.s)); };
Int operator / (int &o) { return Int(div(s, o)); };
friend ostream& operator << (ostream &out, const Int& x) {
out << x.s.back();
for(int i = x.s.size() - 2; i >= 0;i--){
char buf[20];
sprintf(buf,"%04d",x.s[i]);//08d此处的8应该与WIDTH一致
for(int j=0;j<strlen(buf);j++)out<<buf[j];
}
return out;
}
friend istream& operator >> (istream & in, Int & x){
string s;
if(!(in>>s))return in;
x = s;
return in;
}
private:
bool compare(const vector<int> &A, const vector<int> &B) {
if(A.size() != B.size()) return A.size() < B.size();
for(int i = A.size() - 1; i >= 0; i--){
if(A[i] != B[i]) return A[i] < B[i];
}
return false; // 相等
}
vector<int> add(const vector<int> &A, const vector<int> &B) {
if(A.size() < B.size()) return add(B, A);
vector<int> C;
int t = 0;
for(int i = 0; i < A.size(); i++){
if(i < B.size()) t += B[i];
t += A[i];
C.push_back(t % BASE);
t /= BASE;
}
if(t) C.push_back(t);
adjust(C);
return C;
}
vector<int> sub(const vector<int> &A, const vector<int> &B) {
vector<int> C;
for(int i = 0, t = 0; i < A.size(); i++){
t = A[i] - t;
if(i < B.size()) t -= B[i];
C.push_back((t + BASE) % BASE);
t = t < 0 ? 1 : 0;
}
adjust(C);
return C;
}
vector<int> mul(const vector<int> &A, const int& B) {
vector<int> C;
int t = 0;
for(int i = 0; i < A.size() || t; i ++) {
if(i < A.size()) t += A[i] * B;
C.push_back(t % BASE);
t /= BASE;
}
adjust(C);
return C;
}
vector<int> mul(const vector<int> &A, const vector<int> &B) {
int a = A.size(), b = B.size();
vector<int> C(a + b + 10, 0);
for(int i = 0; i < a; i ++) {
for(int j = 0; j < b; j++){
C[i + j] += A[i] * B[j];
}
}
for(int i = 0; i < C.size(); i++){
if(C[i] >= BASE) {
C[i + 1] += C[i] / BASE;
C[i] %= BASE;
}
}
adjust(C);
return C;
}
vector<int> div(const vector<int> &A, const int &B) {
vector<int> C;
int r = 0;
for(int i = A.size() - 1; i >= 0; i--) {
r = r * BASE + A[i];
C.push_back(r / B);
r %= B;
}
reverse(C.begin(), C.end());
adjust(C);
transform(this->r, r);
return C;
}
vector<int> div(vector<int> A, vector<int> B){
int a = A.size(), b = B.size();
int dv = a - b;
vector<int> C(dv + 1, 0);
reverse(B.begin(), B.end());
for(int i = 0; i < dv; i++) B.push_back(0);
reverse(B.begin(), B.end());
b = a;
for(int i = 0; i <= dv; i++){
while(!compare(A, B)) {
A = sub(A, B);
C[dv - i] ++;
}
B.erase(B.begin());
}
this->r = A;
adjust(C);
return C;
}
void transform(vector<int> &A, long long B){
A.clear();
do {
A.push_back(B % BASE);
B /= BASE;
} while(B > 0);
}
void adjust(vector<int> &A) {
while(A.size() > 1 && A.back() == 0) A.pop_back();
}
static const int BASE = 10000;
static const int WIDTH = 4;
vector<int> s;
vector<int> r;
};
int main(){
scanf("%d", &n);
rep(i,0,n) {
scanf("%d%d", &a[i].first, &a[i].second);
}
sort(a + 1, a + 1 + n, [](pair<int,int> a, pair<int,int> b) { return a.first * a.second < b.first * b.second; });
Int rs = 0, now = 0, pre = a[0].first;
rep(i,1,n) {
if(a[i].second != 0) now = pre / a[i].second;
if(a[i].first == 0) break;
pre = pre * a[i].first;
if(rs < now) rs = now;
}
cout << rs << endl;
return 0;
}
给树染色
一颗树有 个节点,这些节点被标号为:,每个节点 都有一个权值 。
现在要把这棵树的节点全部染色,染色的规则是:
根节点 可以随时被染色;对于其他节点,在被染色之前它的父亲节点必须已经染上了色。
每次染色的代价为 ,其中 代表当前是第几次染色。
求把这棵树染色的最小总代价。
输入格式
第一行包含两个整数 和 ,分别代表树的节点数以及根节点的序号。
第二行包含 个整数,代表所有节点的权值,第 个数即为第 个节点的权值 。
接下来 行,每行包含两个整数 和 ,代表两个节点的序号,两节点满足关系: 节点是 节点的父节点。
除根节点外的其他 个节点的父节点和它们本身会在这 行中表示出来。
同一行内的数用空格隔开。
输出格式
输出一个整数,代表把这棵树染色的最小总代价。
数据范围
,
输入样例:
5 1
1 2 1 2 4
1 2
1 3
2 4
3 5
输出样例:
33
前置知识:并查集
一个贪心思路是每次从当前可以染色的集合中选择一个权值最大的点进行染色。但这样的策略是错误的,很容易构造一个极端的例子——让一个权值很小的节点下边有很多权值巨大的结点,另一个权值较大的节点却没有子节点。
有一个重要的性质:整个树中,除去根结点外权值最大的点一定会在其父节点染色后立即染色。
于是可以将其与父节点“合并起来”。合并得到的新点权值设置为这两个点的权值的平均值。
合并这个操作可以使用并查集,每个集合中包含了集合内部的染色顺序。
总体复杂度
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=int(j);i<=int(k);i++)
#define per(i,j,k) for(int i=int(j);i>=int(k);i--)
typedef long long ll;
const int N = 1010;
int n, rt, val[N], f[N], fat[N];
struct Node {
int v, s;
vector<int> ord;
}a[N];
int get(int x){ return x == f[x] ? x : f[x] = get(f[x]); }
int main(){
scanf("%d%d", &n, &rt);
rep(i,1,n) {
scanf("%d", &a[i].v);
a[i].s = 1;
a[i].ord = {i};
val[i] = a[i].v;
f[i] = i;
}
rep(i,1,n-1) {
int x, y; scanf("%d%d", &x, &y);
fat[y] = x;
}
rep(i,1,n-1) {
int x = -1, v = -1, s = 1;
rep(j,1,n) {
if(j != rt && (x == -1 || (v * a[j].s < a[j].v * s))) {
x = j, v = a[j].v, s = a[j].s;
}
}
int fa = get(fat[x]);
a[fa].v += a[x].v; a[fa].s += a[x].s;
a[fa].ord.insert(a[fa].ord.end(), a[x].ord.begin(), a[x].ord.end());
a[x].ord.clear();
a[x].v = -1; a[x].s = 1;
f[x] = fa;
}
int rs = 0;
for(int i = 0; i < a[rt].ord.size(); i++){
rs += (i + 1) * val[a[rt].ord[i]];
}
printf("%d\n", rs);
return 0;
}
另外,结构体中的 ord 可以省去。采用前缀累计贡献的思考方式计算答案:
总体复杂度没有变,常数变小。
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=int(j);i<=int(k);i++)
#define per(i,j,k) for(int i=int(j);i>=int(k);i--)
typedef long long ll;
const int N = 1010;
int n, rt, rs, f[N], fat[N];
struct Node {
int v, s;
}a[N];
int get(int x){ return x == f[x] ? x : f[x] = get(f[x]); }
int main(){
scanf("%d%d", &n, &rt);
rep(i,1,n) {
scanf("%d", &a[i].v);
rs += a[i].v;
a[i].s = 1;
f[i] = i;
}
rep(i,1,n-1) {
int x, y; scanf("%d%d", &x, &y);
fat[y] = x;
}
rep(i,1,n-1) {
int x = -1, v = -1, s = 1;
rep(j,1,n) {
if(j != rt && (x == -1 || (v * a[j].s < a[j].v * s))) {
x = j, v = a[j].v, s = a[j].s;
}
}
int fa = get(fat[x]);
rs += a[fa].s * a[x].v;
a[fa].v += a[x].v; a[fa].s += a[x].s;
a[x].v = -1; a[x].s = 1;
f[x] = fa;
}
printf("%d\n", rs);
return 0;
}