UVa 10131 - Is Bigger Smarter?
来源:互联网 发布:香蕉网络电视 编辑:程序博客网 时间:2024/05/16 01:45
次题是将elephant的体重按升续排列,然后求IQ的最长下降子序列。次题的难点在于如何记录id,并且输出。。。
// File Name: UVa10131.cpp// Author: Toy// Created Time: 2013年04月08日 星期一 11时30分15秒#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <cctype>#include <cmath>#include <string>#include <algorithm>#include <cstdlib>#include <iomanip>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <utility>#include <bitset>#define L(x) x << 1#define R(x) x << 1 | 1using namespace std;struct Ele { int we, iq, id;}ele[1005];bool cmp ( Ele a, Ele b ) { if ( a.we == b.we ) return a.iq < b.iq; else return a.we < b.we;}void output ( int p[], int ipo ) { if ( ipo == 0 ) return; output ( p, p[ipo] ); printf ( "%d\n", ele[ipo].id );}int opt[1005], path[1005];int main ( ) { int tmp = 1; while ( scanf ( "%d%d", &ele[tmp].we, &ele[tmp].iq ) != EOF ) ele[tmp].id = tmp++; memset ( path, 0 ,sizeof ( path ) ); memset ( opt, 0, sizeof ( opt ) ); sort ( ele + 1, ele + tmp, cmp ); //for ( int i = 1; i < tmp; ++i ) //printf ( "%d %d\n", ele[i].we, ele[i].iq ); ele[0].iq = 10000; for ( int i = 1; i < tmp; ++i ) for ( int j = i - 1; j >= 0; --j ) if ( ele[j].iq > ele[i].iq && opt[j] + 1 > opt[i] ) opt[i] = opt[j] + 1, path[i] = j; int ii, ans = 0; for ( int i = 1; i < tmp; ++i ) if ( opt[i] > ans ) ans = opt[i], ii = i; printf ( "%d\n", ans ); output ( path, ii ); return 0;}
- UVa 10131 Is Bigger Smarter?
- UVa 10131 Is Bigger Smarter?
- UVA 10131 - Is Bigger Smarter
- uva 10131 Is Bigger Smarter?
- uva:10131 - Is Bigger Smarter?
- uva 10131 Is Bigger Smarter?
- UVA 10131 Is Bigger Smarter?
- UVA 10131 Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- Uva - 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter
- UVa 10131: Is Bigger Smarter?
- UVa:10131 Is Bigger Smarter?
- UVA - 10131 Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- 版图再重整,手机芯片市场谁能笑到最后?
- js中数值转换,判断是否为浮点数
- 项目管理-需求设计
- 农民工为何要重复交医保和新农合
- ios view 画图
- UVa 10131 - Is Bigger Smarter?
- ecshop nginx下实现url静态化
- Linux目录,文件,权限管理
- Javascript学习笔记-----运算符
- iOS 5 ARC 入门
- 项目管理-开发阶段
- (备忘)linux编程推荐书籍
- java根据url生成网页截图,缩略图
- 命令行发送&接收电子邮件