POJ之路13-POJ2388
2015-07-04 13:36
246 查看
一、poj2388
求取中位数,即排序然后输出中间的数即可。一次ac的代码如下:
求取中位数,即排序然后输出中间的数即可。一次ac的代码如下:
//79ms
#include<string> #include<fstream> #include<algorithm> using namespace std; int main() { // ifstream cin("data.txt"); int n,i; int a[10001]; cin>>n; for(i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n); cout<<a[n/2]<<endl; return 0; }或者用快排,代码如下:
#include<iostream> #include<fstream> #include<algorithm> using namespace std; int cmp(void const*a,void const*b) { return *(int*)a-*(int*)b; } int main() { // ifstream cin("data.txt"); int n,i; int a[10001]; while(cin>>n) { for(i=0;i<n;i++) { cin>>a[i]; } qsort(a,n,sizeof(a[0]),cmp); cout<<a[n/2]<<endl; } return 0; }
相关文章推荐
- chown与chomd区别
- 在vim中使用zencoding/Emmet
- 初探linux内存管理
- 自定制模版
- Lua的线程和状态
- Lucas定理
- wget批量下载
- MySQL分区性能初探
- 前端工具(sublime)
- wamp -- php集成环境搭建
- wamp -- php集成环境搭建
- wamp -- php集成环境搭建
- LR:Code - 60990,Code - 10343 问题解决
- C#同步SQL Server数据库Schema
- apache、php -- 环境配置问题
- apache、php -- 环境配置问题
- apache、php -- 环境配置问题
- Tomcat扩展——监控
- interface 接口 和多态的含义
- INFO: task ftest07:1247 blocked for more than 120 seconds 深入探索