ural 2021 Scarily interesting!(贪心)
2021. Scarily interesting!
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
5 |
5 1 |
Problem Source: NEERC 2014, Eastern subregional contest
All submissions (1925) All accepted submissions (506) Solutions rating (362)
#include <bits/stdc++.h>
using namespace std; const int MAXN = ; vector<int> vt1[];
vector<int> vt2[]; vector<int> vt3;
vector<int> vt4; int main()
{
int n;
int i;
int a, b;
vector<int>::iterator it1, it2;
int sum1, sum2; while (~scanf("%d", &n)) {
for (i = ; i <= ; ++i) {
vt1[i].clear();
vt2[i].clear();
}
vt3.clear();
vt4.clear();
sum1 = ;
sum2 = ;
for (i = ; i <= n; ++i) {
scanf("%d", &a);
vt1[a].push_back(i);
sum1 += a;
}
for (i = ; i <= n; ++i) {
scanf("%d", &b);
vt2[b].push_back(i);
sum2 += b;
}
// printf("debug 1\n");
for (i = ; i <= ; ++i) {
it1 = vt1[i].begin();
it2 = vt2[i].begin();
if (vt1[i].size() < vt2[i].size()) {
while (it1 < vt1[i].end()) {
printf("%d %d\n", *it1++, *it2++);
}
while (it2 < vt2[i].end()) {
vt4.push_back(*it2++);
}
} else {
// printf("debug 3\n");
while (it2 < vt2[i].end()) {
printf("%d %d\n", *it1++, *it2++);
}
while (it1 < vt1[i].end()) {
vt3.push_back(*it1++);
}
}
}
// printf("debug 2\n"); if (sum1 > sum2) {
it1 = vt3.begin();
it2 = vt4.end() - ;
while (it1 < vt3.end()) {
printf("%d %d\n", *it1++, *it2--);
}
} else {
it1 = vt3.end() - ;
it2 = vt4.begin();
while (it2 < vt4.end()) {
printf("%d %d\n", *it1--, *it2++);
}
} } return ;
}
ps:自己没想到这样做啊,
我的思路是让双方的分差越小越好,但是不知道这样做对不,写起来也比较复杂。
ural 2021 Scarily interesting!(贪心)的更多相关文章
- URAL 2021 Scarily interesting! (贪心+题意)
题意:给定两个队伍的每个人的得分,让你安排怎么比赛才能使得观众知道冠军的时间最长. 析:贪心,很简单,就是先开始总分高的先出最差劲的,总分低的先出最厉害的,这个题当时实在是读的不明白啊,WA了好多次. ...
- Gym 100507J Scarily interesting! (贪心)
Scarily interesting! 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/D Description This y ...
- J - Scarily interesting! URAL - 2021
This year at Monsters University it is decided to arrange Scare Games. At the Games all campus gathe ...
- Scarily interesting! (URAL - 2021)
Problem This year at Monsters University it is decided to arrange Scare Games. At the Games all camp ...
- ural 1303 Minimal Coverage(贪心)
链接: http://acm.timus.ru/problem.aspx?space=1&num=1303 按照贪心的思想,每次找到覆盖要求区间左端点时,右端点最大的线段,然后把要求覆盖的区间 ...
- URAL 1995 Illegal spices 贪心构造
Illegal spices 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1995 Description Jabba: Han, m ...
- Ural 2070:Interesting Numbers(思维)
http://acm.timus.ru/problem.aspx?space=1&num=2070 题意:A认为如果某个数为质数的话,该数字是有趣的.B认为如果某个数它分解得到的因子数目是素数 ...
- NEERC 2014, Eastern subregional contest
最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...
- Contest 7.21(贪心专练)
这一次都主要是贪心练习 练习地址http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#overview Problem APOJ 13 ...
随机推荐
- Python中何时使用断言(转)
原文:http://blog.jobbole.com/76285/ 本文由 伯乐在线 - 贱圣OMG 翻译.未经许可,禁止转载!英文出处:python maillist.欢迎加入翻译小组. 这个问题是 ...
- Python3 面向对象(1)
面向.概述 面向过程: 根据业务逻辑从上到下写垒代码面向过程的设计的核心是过程,过程即解决问题的步骤, 面向过程的设计就好比精心设计好一条流水线,考虑周全什么时候处理什么东西 优点: 极大降低了程序的 ...
- 关于handler内存泄露的问题
在使用Handler更新UI的时候.我是这样写的: public class SampleActivity extends Activity { private final Handler mLeak ...
- Python基础-configparser和hashlib模块
configparser模块 import configparser config = configparser.ConfigParser() #将配置写入到文件 config[', 'Compres ...
- oracle修改连接数后无法启动(信号量的问题)
当oracle11g修改最大连接数后启动报如下错误时,需要调整linux的信号量的内核参数: ORA-27154: post/wait create failedCause: internal err ...
- ajax图片上传功能
一.应用场景 当用户需要上传图片当做自己的头像时,预览的时候该图片需要在本地预览,不应该通过网络从服务器上取到之后预览 二.实现方法 1.方法1: 注释:给上传文件的input标签绑定一个change ...
- Python Variable Scope
Python中的变量的作用域有时会让像我这样的初学者很头疼. 其实只需要掌握以下两点: 1. Python能够改变变量作用域的代码段是def.class.lamda; 而if/elif/else ...
- jquery 字符串转为json
使用ajax从服务器拿到的数据,jquery总是认为是字符串,无法直接使用,可以通过下面代码转换: $.get("服务器路径", function(data) { data = e ...
- LeetCode:寻找数组的中心索引【668】
LeetCode:寻找数组的中心索引[668] 题目描述 给定一个整数类型的数组 nums,请编写一个能够返回数组“中心索引”的方法. 我们是这样定义数组中心索引的:数组中心索引的左侧所有元素相加的和 ...
- problem-1003(恢复一下)
问题: Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequenc ...