J - Scarily interesting!

2023-12-28 08:18
文章标签 interesting scarily

本文主要是介绍J - Scarily interesting!,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题意:

两个队进行比赛,每个队n个人,现在已知每个人会得多少分。每个人的得分不超过6。比赛进行n回合,每个回合一个队派一个人参赛,每个人只能参赛一次。一个队伍前i个回合的总得分为该队伍派出的前i个人的得分和。现在让你输出一个方案,让比赛尽量不失去悬念。假设第i回合比赛已经没有悬念,那么我们需要输出一个方案,让i尽量的大。

思路:
一看就是贪心题,哎,贪心思路不对,我和队友把它按照先输出相同的来贪的,结果WA!!其实正确的贪心是首先判断两个队伍谁最终会获胜。对于最后会输的队伍,从最强的人派出来参赛,对于最后会赢的队伍,先派最弱的人参赛,这样让比赛上演逆转,悬念一定能保持得最久!!明白这一点题目就很简单!!!

代码:

#include <bits/stdc++.h>
using namespace std;
#define maxn 1005
struct node{int point;int id;
}a[maxn],b[maxn];
bool cmp(node aa,node bb)
{return aa.point<bb.point;
}
bool cmp1(node aa,node bb)
{return aa.point>bb.point;
}
int main()
{int i,j,n,suma,sumb;while(cin>>n){suma=0;sumb=0;for(i=1;i<=n;i++){cin>>a[i].point;suma+=a[i].point;a[i].id=i;}for(j=1;j<=n;j++){cin>>b[j].point;sumb+=b[j].point;b[j].id=j;}if(suma>sumb)//即a会赢{sort(a+1,a+1+n,cmp);sort(b+1,b+1+n,cmp1);for(i=1;i<=n;i++)cout<<a[i].id<<' '<<b[i].id<<endl; }else {sort(a+1,a+1+n,cmp1);sort(b+1,b+1+n,cmp);for(i=1;i<=n;i++)cout<<a[i].id<<' '<<b[i].id<<endl; }
}return 0;
}

心得:::

贪心贪的要准啊啊啊啊啊啊啊

这篇关于J - Scarily interesting!的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/545403

相关文章

Codeforces Round #275 (Div. 1) B.Interesting Array

线段树维护: 维护最小的区间内满足条件的值 模板题,将所有的区间插入完成之后再将每一个query的值check遍 #include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>

NSSCTF中的popchains、level-up、 What is Web、 Interesting_http、 BabyUpload

目录 [NISACTF 2022]popchains  [NISACTF 2022]level-up  [HNCTF 2022 Week1]What is Web [HNCTF 2022 Week1]Interesting_http  [GXYCTF 2019]BabyUpload 今日总结: [NISACTF 2022]popchains  审计可以构造pop链的代码

HDU 2426 Interesting Housing Problem(KM完美匹配)

HDU 2426 Interesting Housing Problem 题目链接 题意:n个学生,m个房间,给定一些学生想住房的喜欢度,找一个最优方案使得每个学生分配一个房间,并且使得喜欢度最大,注意这题有个坑,就是学生不会住喜欢度为负的房间 思路:很明显的KM最大匹配问题,喜欢度为负直接不连边即可 代码: #include <cstdio>#include <cst

[BJDCTF 2020]easy_md5、[HNCTF 2022 Week1]Interesting_include、[GDOUCTF 2023]泄露的伪装

目录 [BJDCTF 2020]easy_md5 ffifdyop [SWPUCTF 2021 新生赛]crypto8 [HNCTF 2022 Week1]Interesting_include php://filter协议 [GDOUCTF 2023]泄露的伪装 [BJDCTF 2020]easy_md5 尝试输入一个1,发现输入的内容会通过get传递但是没有其他回显 观察

2019年1-4月份雅思口语题库素材(原创)describe an interesting persion you would like to meet

About a year ago, I came to Bali, Indonesia, as an international volunteer with my classmates. Our work is mainly to help sea turtles breed and clean the beach. But we haven’t been to Bali, so we do

Fw:An interesting Poem of C Language (extracts with a new title)

//Via:  http://www.guokr.com/post/61543/ #include<stdio.h> void main() { double world; unsigned letter; short stay; long memories; printf("I miss you.[color=orange]\n"[/color]); } //意境很

Codeforces 102394I Interesting Permutation (脑洞)

I. Interesting Permutation time limit per test 1 second memory limit per test 512 megabytes DreamGrid has an interesting permutation of 1,2,…,n denoted by a1,a2,…,an. He generates three sequences f,

ACM 数论 Interesting Integers

题目: Undoubtedly you know of the Fibonacci numbers. Starting with F_1 = 1F1​=1 and F_2 = 1F2​=1,every next number is the sum of the two previous ones. This results in the sequence 1, 1, 2, 3, 5, 8

Interesting Array CodeForces - 483D(思维+线段树)

We’ll call an array of n non-negative integers a[1], a[2], …, a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning

[HNCTF 2022 Week1]Interesting_http

[HNCTF 2022 Week1]Interesting_http wp 题目页面: 提示 POST 发包,参数名为 want 。 POST 发包 want=1 : POST 发包 want=flag : 提示当前非 admin 用户。 抓包看看: cookie 处写着 notadmin ,将其修改为 admin 再发包: 提示非本地。 添加 XFF 头: