zoukankan      html  css  js  c++  java
  • Codeforces Round #503 (by SIS, Div. 2)

    连接:http://codeforces.com/contest/1020

    C.Elections

    题型:你们说水题就水题吧...我没有做出来...get到了新的思路,不虚。好像还有用三分做的?

    KN Point(注意复杂度性能):优先队列1优先队列2

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define ll long long
     4 const int inf=3e3+10;
     5 priority_queue<int,vector<int>,greater<int> >tep[inf],s[inf],S; //优先队列
     6 ll ans=1e18;
     7 int main()
     8 {
     9     ios::sync_with_stdio(0);
    10     int n,m;
    11     cin>>n>>m;
    12     for(int i=1;i<=n;i++)
    13     {
    14         int c,p;
    15         cin>>c>>p;
    16         s[c].push(p);
    17     }
    18     for(int i=1;i<=n;i++)  //索性枚举所有胜出可能需要拥有的票数,就不用考虑到底到底贿赂谁了
    19     {
    20         ll v=0;int cnt=s[1].size();
    21         while(!S.empty()) S.pop();         
    22         for(int j=2;j<=m;j++) tep[j]=s[j];
    23 
    24         for(int j=2;j<=m;j++)  //复杂度不会算了,有没有人教一下,感觉整个程序的复杂度在 n^2*log(n)左右      
    25             while(tep[j].size()>=i)
    26               v+=tep[j].top(),tep[j].pop(),cnt++;  //让所有除1以外的所有人需要减掉的票数
    27         for(int j=2;j<=m;j++)
    28             while(!tep[j].empty())
    29                 S.push(tep[j].top()),tep[j].pop();  //存下剩下的票数
    30         while(cnt<i&&!S.empty())
    31             cnt++,v+=S.top(),S.pop();  //用剩下的票数使得1的票数大于等于所需要的票数
    32         if(cnt>=i) ans=min(ans,v);
    33     }
    34     cout<<ans<<endl;
    35 }
  • 相关阅读:
    如何理解面向对象和面向过程
    IIS端口被占用
    SQL UNION操作符
    SQL(MSSQLSERVER)服务启动错误代码3414
    WCF学习之路(一)
    AJAX技术学习总结
    AJAX之XMLHttpRequest对象
    软考之汇编语言
    IP地址的分配
    数组偏移量
  • 原文地址:https://www.cnblogs.com/LLbinGG/p/9479972.html
Copyright © 2011-2022 走看看