J - Scarily interesting! URAL - 2021

This year at Monsters University it is decided to arrange Scare Games. At the Games all campus gathers at the stadium stands, and the Scare program students divide into two teams to compete in their abilities of scaring children. This year the two teams will be “Oozma Kappa” and “Roar Omega Roar”.

Each team has n monsters, and the Games consist of n challenges. During each challenge Dean Hardscrabble, the chair of the Scare program, invites one monster from each team to demonstrate his mastery. Each of the monsters is invited only once and scores from 0 to 6 points, depending on how much a child is scared. The results of each challenge are announced at the same time for both monsters right after the end of this challenge. The winning team will be identified by the sum of the points scored by all its members.

Sports competition is an unpredictable process. But the Dean wants to keep all the course of the Games under control, so that the identity of the winning team will have been unclear for the audience as long as possible. For example, if six challenges until the end “Oozma Kappa” is forty points ahead, the audience at the stadium stands will just lose interest to the game. The Dean knows the skill level of all her students, and she wants to decide beforehand the order in which both teams’ members will be participating in the challenges. In what order should monsters from “Oozma Kappa” and from “Roar Omega Roar” show up to keep the audience in suspense as long as possible?

Input

The first line contains an integer n (2 ≤ n ≤ 1 000). The second line contains n integers within the range from 0 to 6, which are the points monsters from “Oozma Kappa” will score. The third line contains the points, monsters from “Roar Omega Roar” will score, written in the same manner.

Output

Output n lines, each containing integers o i and r i, which are the numbers of monsters from “Oozma Kappa” and “Roar Omega Roar” respectively, who should be called by the Dean to take part in the i-th challenge. In each team monsters are numbered with integers from 1 to n in the order they appear in the input data. If the problem has several solutions, output any of them.

Example

input output
5
0 1 4 3 6
6 5 1 3 0
5 1
1 5
4 4
2 3
3 2

Hint

/*
* @Author: lyuc
* @Date:   2017-04-30 16:02:54
* @Last Modified by:   lyuc
* @Last Modified time: 2017-04-30 16:37:02
*/
/**
 * 题意:两个队伍比赛,每次每队派一名怪兽出来,已知每个怪兽能获得分数,最后分数高的队伍获胜
 *         为了比赛的悬念尽可能的留在最后,请你安排怪兽出场的顺序
 *
 * 思路:首先统计一下每个队伍的每个队伍的得分,肯定分数多的获胜,然后分数多的队伍从小到大输
 *         出,分数少的从大到小输出
 */
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
struct node{
    int id,val;
}a[1005],b[1005];
int n;
bool cmp1(node a,node b){
    return a.val<b.val;
}
bool cmp2(node a,node b){
    return a.val>b.val;
}
int res1,res2;
void init(){
    res1=0;
    res2=0;
}
int main(){
    // freopen("in.txt","r",stdin);
    init();
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        a[i].id=i+1;
        scanf("%d",&a[i].val);
        res1+=a[i].val;
    }
    for(int i=0;i<n;i++){
        b[i].id=i+1;
        scanf("%d",&b[i].val);
        res2+=b[i].val;
    }
    if(res1>res2){
        sort(a,a+n,cmp1);
        sort(b,b+n,cmp2);
        for(int i=0;i<n;i++){
            printf("%d %d\n",a[i].id,b[i].id);
        }
    }else{
        sort(a,a+n,cmp2);
        sort(b,b+n,cmp1);
        for(int i=0;i<n;i++){
            printf("%d %d\n",a[i].id,b[i].id);
        }
    }
    return 0;
}
时间: 2024-10-11 00:24:25

J - Scarily interesting! URAL - 2021的相关文章

ural 2021 Scarily interesting!

2021. Scarily interesting! Time limit: 1.0 secondMemory limit: 64 MB This year at Monsters University it is decided to arrange Scare Games. At the Games all campus gathers at the stadium stands, and the Scare program students divide into two teams to

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

题意:给定两个队伍的每个人的得分,让你安排怎么比赛才能使得观众知道冠军的时间最长. 析:贪心,很简单,就是先开始总分高的先出最差劲的,总分低的先出最厉害的,这个题当时实在是读的不明白啊,WA了好多次. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include

HDOJ-ACM1023(JAVA)

题意:输入栈的大小,输出可能的出栈顺序的个数. 这道题,如果做了1022,那就只要在上面改改就行了, 第一想法是加上全排列-----结果是正确的,但是绝对会超时 验证性的实现了:(Time Limit Exceeded) import java.util.*; import java.io.*; public class Main{ public static void main(String[] arg){ Scanner scan = new Scanner(new BufferedInpu

【线性筛】【筛法求素数】【约数个数定理】URAL - 2070 - Interesting Numbers

素数必然符合题意. 对于合数,如若它是某个素数x的k次方(k为某个素数y减去1),一定不符合题意.只需找出这些数. 由约数个数定理,其他合数一定符合题意. 就从小到大枚举素数,然后把它的素数-1次方都排除即可. #include<cstdio> #include<cmath> using namespace std; #define MAXP 1000100 #define EPS 0.00000001 typedef long long ll; ll L,R; bool isNo

URAL 2070 Interesting Numbers(数学)

题目地址:http://acm.timus.ru/problem.aspx?space=1&num=2070 思路:质数一定满足题意(满足条件一,因子数为2为质数).所以只需求出l到r中的合数且因子数为质数的数的个数.该数质因子只能为1(若大于一,则因子数为合数),所以枚举每个质数,若该质数的指数+1(因子数)为质数,则ans--. #include<cstdio> #include<vector> #include<cstring> #include<i

URAL 2070 Interesting Numbers (找规律)

题意:在[L, R]之间求:x是个素数,因子个数是素数,同时满足两个条件,或者同时不满足两个条件的数的个数. 析:很明显所有的素数,因数都是2,是素数,所以我们只要算不是素数但因子是素数的数目就好,然后用总数减掉就好.打个表,找找规律,你会发现, 这些数除外的数都是素数的素数次方,然后就简单了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include &

URAL 2026 Dean and Schedule 贪心、双端队列(deque)、队列(queue)

C - Dean and Schedule Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 2026 Description A new academic year approaches, and the dean must make a schedule of classes for first-year students. Ther

ural 1353. Milliard Vasya&#39;s Function

点击打开链接 1353. Milliard Vasya's Function Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning mathematician. He decided to make an important contribution to the science and to become famous all over the world. But how can he do that if the

Ural 1081 Binary Lexicographic Sequence(DP)

题目地址:Ural 1081 先用dp求出每个长度下的合法序列(开头为1)的个数.然后求前缀和.会发现正好是一个斐波那契数列.然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #in