zoukankan      html  css  js  c++  java
  • sgu548

    http://acm.sgu.ru/problem.php?contest=0&problem=548 还是太弱了,只会模板题和水题,稍微需要思考的就不会了,跟江哥讨论了一下午,还问了两个牛,才搞懂。。。 自己想偏了一些,总是卡在最后一步上,以后要从多个方向想问题,前后。。。 [code lang="cpp"] #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <cassert> #include <iostream> #include <sstream> #include <fstream> #include <map> #include <set> #include <vector> #include <queue> #include <algorithm> #include <iomanip> #define maxn 210000 using namespace std; int n; int f[maxn]; int wei[maxn]; struct node {     char op[5];     int x;     int id;     bool operator< (const node &a) const     {         return x<a.x;     } } a[maxn]; int last,ff; int num; priority_queue<node> xx; int res,no; int ans[maxn]; int main() {     char ch[5];     int x;     node tmp;     while(scanf("%d",&n)!=EOF)     {         num = 1 ;         wei[1] = 1;         for(int i=2 ; i<=n ; i++)         {             scanf("%s%d",ch,&x);             strcpy(a[i].op,ch);             strcpy(a[i].op,ch);             a[i].x = x;             a[i].id = i;             if(ch[0]=='p')             {                 num ++;                 wei[num] = i;             }         }         for(int i= 0 ; i<= n ; i++) f[i] = -1;         f[1] = 1;         f[wei[num-1]] = a[wei[num-1]].x;         for(int i = num - 2 ; i >= 2; i -- )         {             f[wei[i]] = min(f[wei[i+1]],a[wei[i]].x);         }         res = 0;         no = 0;         while(!xx.empty()) xx.pop();         last = wei[ num - 1 ];         int  i;         i = num - 1;         while( i >= 1 )         {             if(last == - 1) last = wei[i];             for(int j = wei[i] + 1 ; j < last; j ++)             {                 if(a[j].op[0]=='d') xx.push(a[j]);             }             int sec;             sec = f[last] - f[wei[i]];             if(sec > 0)                 while(sec-- && !xx.empty())   //!!!!!!!空的话再往外top或pop就会re                 {                     tmp = xx.top();                     res += tmp.x;                     no++;                     ans[no] = tmp.id;                     xx.pop();                 }             last = wei[i];             i --;         }         for(int j = wei[ num - 1 ] + 1 ; j < n ; j ++)         {             res += a[j].x;             no ++;             ans[no] = a[j].id;         }         if(no < a[n].x)         {             printf("-1\n");         }         else         {             printf("%d\n",res);             printf("%d\n",no);             sort(ans+1,ans+no+1);             for(i=1 ; i<=no; i++) printf("%d ",ans[i]);             printf("\n");         }     }     return 0; } [/code] 我的空格被吃掉了,好可恶。。。。 用IE写就好了。。。

  • 相关阅读:
    Android-实现切换Fragment页功能
    Mybatis中insert返回主键ID
    ScrollView 与ListView 滑动冲突完美解决
    fresco的源码学习自我总结
    React-Native错误笔记-EPERM
    React-Native的基本控件属性方法
    React Native之ViewPagerAndroid跳转页面问题
    Android应用中-更新提示显示红点的方案
    关于GrideView Item点击后出现错乱重叠的情况
    分享一个Unity3D小作品,源码地址已公布在文章开头!
  • 原文地址:https://www.cnblogs.com/jh818012/p/3182675.html
Copyright © 2011-2022 走看看