July 15th 模拟赛C T3 最小最大和 Solution
来源:互联网 发布:c语言求质因数 编辑:程序博客网 时间:2024/06/07 09:37
空降题目处
点我点我点我
Description:
Alice和Bob在玩一个游戏,每一轮Bob都会给Alice两个整数A和B(1<=A,B<=100),Alice每一轮必须把目前所有的A序列和B序列中的数一一配对,每个数必须用且只使用一次,要求最大和最小。
Input
第一行一个整数N(1<=N<=100000),表示比赛的轮数。
接下来N行每行包含两个整数A和B(1<=A,B<=100),表示Bob这一轮给的两个数。
Output
输出N行,每行输出最小的最大和。
Solution
堆排,反正我没试过。
往下拉
好吧,正解来了。
有指针
……
详见BIAO
Program
C++
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>using namespace std;int ans,n,x,y,t,a[102],b[102],c[102],d[102];int main(){ scanf("%d",&n); for (int k=1;k<=n;k++) { scanf("%d%d",&x,&y); c[x]++; d[y]++; memcpy(a,c,sizeof(c)); memcpy(b,d,sizeof(d)); ans=x=0; y=101; while ((x<=100)&&(y>=1)) { while ((a[x]==0)&&(x<=100)) x++; if (x>100) break; while ((b[y]==0)&&(y>=1)) y--; if (y<1) break; if (a[x]<b[y]) { ans=max(ans,x+y); b[y]-=a[x]; a[x]=0; } else { ans=max(ans,x+y); a[x]-=b[y]; b[y]=0; } } printf("%d\n",ans); }}
Pascal
uses math;var ans,n,x,y,t,k:longint; c,d,a,b:array [0..101] of longint;begin readln(n); for k:=1 to n do begin readln(x,y); inc(c[x]); inc(d[y]); a:=c; b:=d; x:=0; y:=101; ans:=0; while (x<=100) and (y>=1) do begin while (a[x]=0) and (x<=100) do inc(x); if x>100 then break; while (b[y]=0) and (y>=1) do dec(y); if y<1 then break; if a[x]<b[y] then begin ans:=max(ans,x+y); b[y]:=b[y]-a[x]; a[x]:=0; end else begin ans:=max(ans,x+y); a[x]:=a[x]-b[y]; b[y]:=0; end; end; writeln(ans); end;end.
0 1
- July 15th 模拟赛C T3 最小最大和 Solution
- July 14th 模拟赛C T3 灌水 Solution
- July 16th 模拟赛C T3 圆周舞蹈 Solution
- July 17th 模拟赛C T3 Circle Solution
- July 15th 模拟赛C T1 游泳池 Solution
- July 15th 模拟赛C T2 积木游戏 Solution
- July 14th 模拟赛C T1 输油管道 Solution
- July 14th 模拟赛C T2 数码问题 Solution
- July 14th 模拟赛C T4 开花 Solution
- July 16th 模拟赛C T1 竞赛排名 Solution
- July 16th 模拟赛C T4 奶牛排队 Solution
- July 17th 模拟赛C T1 Gift Solution
- July 17th 模拟赛C T2 Number Solution
- June 11th 模拟赛C T3 Cowski Solution
- September 10th 模拟赛C T3 雕塑 Solution
- September 17th 模拟赛C T3 石子游戏 Solution
- July 15th 模拟赛C T4 回家(莫名其妙【推荐】) Solution
- July 16th 模拟赛C T2 奶牛晒衣服 Solution
- CGI的原理与实现
- HelloWorld
- 建造者模式
- <gs:video-vod>和<gs:video-live>是有区别的
- 中国剩余定理CRT (互质)
- July 15th 模拟赛C T3 最小最大和 Solution
- 游戏中的定时器
- context menu
- iOS之HTTPS
- 因式分解的研究
- px,dp,dip,sp的区别
- Scala学习(1)——Scala基础知识
- python+selenium 初体验
- MsgWaitForMultipleObjects