July 15th 模拟赛C T3 最小最大和 Solution
2016-07-15 17:40
417 查看
空降题目处
点我点我点我
接下来N行每行包含两个整数A和B(1<=A,B<=100),表示Bob这一轮给的两个数。
堆排,反正我没试过。
往下拉↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
好吧,正解来了。
100%
Ax,Bx为统排,计算数x在数列A,B中出现的次数.
有指针P,Q分别从A,B头,尾开始.
……
详见BIAO
Pascal
点我点我点我
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
None%堆排,反正我没试过。
往下拉↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
↓
好吧,正解来了。
100%
Ax,Bx为统排,计算数x在数列A,B中出现的次数.
有指针P,Q分别从A,B头,尾开始.
……
详见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.
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Lua中调用C++函数示例
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++高级程序员成长之路
- C++编写简单的打靶游戏
- C++ 自定义控件的移植问题
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- 使用Lua来扩展C++程序的方法
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C++的template模板中class与typename关键字的区别分析
- C与C++之间相互调用实例方法讲解