2015-07-15 17:28:04

传送门

总结:... 打星的场 赛中 PP 了ABCE,后来C被FST(TLE)了。

  A题... 开场不是很认真... 23min+2WA - -。然后开了C题,用map搞过了,但复杂度n×(logn)^3,最后导致TLE,不能用map。

  随后过了B题。 由于D题比较长... 直接看了E,相了一会发现是线段树暴力,敲了30+min竟然过了编译就AC了,有点意外- -。

  D题没敲完。。赛后用了两种方法补了一下,细节很多,考虑需要很周全,是个好题!

 

A题:排序

#include <cstdio>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)

typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int INF = (1 << 30) - 1;

int n;
pii g[110];
vector<pii > g1,g2;

int main(){
    scanf("%d",&n);
    for(int i = 1; i <= n; ++i){
        scanf("%d%d",&g[i].first,&g[i].second);
    }
    sort(g + 1,g + n + 1);
    int cnt1 = 0,cnt2 = 0;
    for(int i = 1; i <= n; ++i){
        if(g[i].first > 0){
            cnt2++;
            g2.push_back(g[i]);
        }
    }
    for(int i = n; i >= 1; --i){
        if(g[i].first < 0){
            cnt1++;
            g1.push_back(g[i]);
        }
    }
    int cnt = min(cnt1,cnt2);
    int sum = 0;
    for(int i = 0; i < cnt; ++i){
        sum += g1[i].second;
        sum += g2[i].second;
    }
    int maxx = 0;
    if(cnt1 != cnt2){
        if(cnt1 > cnt2) sum += g1[cnt].second;
        else sum += g2[cnt].second;
    }
    printf("%d\n",sum);
    return 0;
}
View Code

相关文章:

  • 2021-06-05
  • 2021-05-30
  • 2022-02-09
  • 2021-08-12
  • 2021-06-13
  • 2021-07-01
  • 2022-01-01
  • 2021-12-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案