Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求大神赐教,,测试了很久,测试结果和别人的一样,就是AC不了代码如下: #include <cstdio> #include <queue> #include <vector> using namespace std ; int main() { priority_queue<int> A; vector<int> big; int M,N; int t[30010]; int u[30010]; scanf("%d%d",&M,&N); for(int i = 1 ; i <= M ; ++i) { scanf("%d",&t[i]); } u[0] = 0; for(int i = 1 ; i <= N ; ++i) { scanf("%d",&u[i]); } for(int i = 1 ; i <= N ; ++i) { for(int j = u[i-1]+1 ; j <= u[i] ; ++j) { A.push(t[j]); } while(i < A.size()) //时刻保证A.top()的值就是get后需要的 { big.push_back(A.top()); A.pop(); } printf("%d\n",A.top()); if( !big .empty() ) //把最小的值压入A中,因为下次第i小的数只会出现在big中和下次要压入A中的数据之间 { A.push(big.back()); big.pop_back(); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator