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 ...
随机推荐
- Laravel 出现"RuntimeException inEncrypter.php line 43: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths."问题的解决办法
如果输入命令:php artisan key:generate 还是报错 那就要从别的项目里复制一个key到.env中,然后再运行命令:composer update和php artisan key: ...
- br_netfilter 模块开机自动方法
环境 cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 在/etc/sysctl.conf中添加: net.bridge.bri ...
- Tomcat日志备份脚本
#!/bin/bash #Author:fansik #Description:backup tomcat logs #Date:-- directory=/usr/local/tomcat/logs ...
- Computer Information
Lab: lxw@lxw-PC:python$ df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/sda7 190G .4G 175G % / none .0K .0K % /sys/ ...
- LeetCode:学生的出勤记录|【551】
LeetCode:学生的出勤记录|[551] 题目描述 给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : P ...
- dataTables的用法
原地址:http://blog.csdn.net/mickey_miki/article/details/8240477 1.DataTables的默认配置 $(document).ready(fun ...
- docker devise相关错误
rake aborted!Devise.secret_key was not set. Please add the following to your Devise initializer: con ...
- ES6 随记(2)-- 解构赋值
上一章请见: 1. ES6 随记(1)-- let 与 const 3. 解构赋值 a. 数组的解构赋值 let [a1, b1, c1] = [1, 2, 3]; console.log(a1, b ...
- Qt浅谈之二十六图片滑动效果
一.简介 博客中发现有作者写的仿360的代码,觉得其中图片滑动的效果很有意思,特提取其中的代码.并加上类似mac的画面移动的动画效果. 二.详解 1.代码一:界面滑动(QWidget) (1)slid ...
- css异步加载
<link rel="preload" href="mystyles.css" as="style" onload="thi ...