首页 > 代码库 > URAL 2021 Scarily interesting! (贪心+题意)

URAL 2021 Scarily interesting! (贪心+题意)

题意:给定两个队伍的每个人的得分,让你安排怎么比赛才能使得观众知道冠军的时间最长。

析:贪心,很简单,就是先开始总分高的先出最差劲的,总分低的先出最厉害的,这个题当时实在是读的不明白啊,WA了好多次。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
  return r >= 0 && r < n && c >= 0 && c < m;
}

struct Node{
  int id, val;
  bool operator < (const Node &p) const{
    return val < p.val;
  }
};
vector<Node> v1, v2;

int main(){
  cin >> n;
  int sum1 = 0, sum2 = 0;
  for(int i = 1; i <= n; ++i){
    scanf("%d", &m);
    v1.push_back((Node){i, m});
    sum1 += m;
  }
  for(int i = 1; i <= n; ++i){
    scanf("%d", &m);
    v2.push_back((Node){i, m});
    sum2 += m;
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  if(sum1 > sum2) for(int i = 0; i < n; ++i) printf("%d %d\n", v1[i].id, v2[n-i-1].id);
  else  for(int i = 0; i < n; ++i) printf("%d %d\n", v1[n-i-1].id, v2[i].id);

  return 0;
}

  

URAL 2021 Scarily interesting! (贪心+题意)