Educational Codeforces Round 95 (Rated for Div. 2) B. Negative Prefixes (贪心,构造)
题意:给你一串长度为\(n\)的序列,有的位置被锁上了,你可以对没锁的位置上的元素任意排序,使得最后一个\(\le0\)的前缀和的位置最小,求重新排序后的序列.
题解:贪心,将所有能动的位置从大到小排个序就行了.
代码:
struct misaka{
int a;
int loc;
}e[N]; int t;
int n; int main() {
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
t=read();
while(t--){
n=read();
for(int i=0;i<n;++i){
e[i].a=read();
}
for(int i=0;i<n;++i){
e[i].loc=read();
} for(int i=0;i<n;++i){
for(int j=0;j<n;++j){
if(e[i].loc!=1 && e[j].loc!=1){
if(e[j].a<e[i].a) swap(e[i],e[j]);
}
}
}
for(int i=0;i<n;++i){
printf("%d ",e[i].a);
}
puts("");
} return 0;
}
Educational Codeforces Round 95 (Rated for Div. 2) B. Negative Prefixes (贪心,构造)的更多相关文章
- Educational Codeforces Round 95 (Rated for Div. 2)
CF的Educational Round (Div.2),质量还是蛮高的. A: 水题 #include<cstdio> #include<algorithm> typedef ...
- Educational Codeforces Round 95 (Rated for Div. 2) C. Mortal Kombat Tower (DP)
题意:你和基友两人从左往右轮流打怪兽,强怪用\(1\)表示,垃圾用\(0\)表示,但基友比较弱,打不过强怪,碰到强怪需要用一次魔法,而你很强,无论什么怪都能乱杀,基友先打,每人每次至少杀一个怪兽,最多 ...
- Educational Codeforces Round 95 (Rated for Div. 2) A. Buying Torches (数学)
题意:刚开始你有一个木棍,造一个火炬需要一个木根和一个煤块,现在你可以用一个木棍换取\(x\)个木棍,或者\(y\)根木棍换一个煤块,消耗一次操作,问最少需要操作多少次才能造出\(k\)把火炬. 题解 ...
- Educational Codeforces Round 81 (Rated for Div. 2) B. Infinite Prefixes
题目链接:http://codeforces.com/contest/1295/problem/B 题目:给定由0,1组成的字符串s,长度为n,定义t = sssssss.....一个无限长的字符串. ...
- Educational Codeforces Round 62 (Rated for Div. 2)E(染色DP,构造,思维,组合数学)
#include<bits/stdc++.h>using namespace std;const long long mod=998244353;long long f[200007][2 ...
- Educational Codeforces Round 33 (Rated for Div. 2) D题 【贪心:前缀和+后缀最值好题】
D. Credit Card Recenlty Luba got a credit card and started to use it. Let's consider n consecutive d ...
- Educational Codeforces Round 77 (Rated for Div. 2)D(二分+贪心)
这题二分下界是0,所以二分写法和以往略有不同,注意考虑所有区间,并且不要死循环... #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> ...
- Educational Codeforces Round 94 (Rated for Div. 2) C. Binary String Reconstruction (构造)
题意:给你一个字符串\(s\),原字符串为\(w\),如果\(i>x\)且\(w_{i-x}=1\),那么\(s_{i}=1\),如果\(i+x\le n\)且\(w_{i+x}=1\),那么\ ...
- Educational Codeforces Round 91 (Rated for Div. 2) B. Universal Solution (贪心)
题意:石头剪刀布,bot有一串字符,表示他要出什么,你需要事先确定你的出招方案,然后遍历bot的字符串,从\(i\)位置开始跑一个循环,每次跑都要记录你赢的次数贡献给\(sum\),现要求\(\fra ...
随机推荐
- kubernets之statefulset资源
一 了解Statefulset 1.1 对比statefulset与RS以及RC的区别以及相同点 Statefulset是有状态的,而RC以及RS等是没有状态的 Statefulset是有序的,拥 ...
- CTFshow-萌新赛杂项_签到
查看网页信息 http://game.ctf.show/r2/ 把网页源码下载后发现有大片空白 使用winhex打开 把这些16进制数值复制到文件中 把20替换为0,09替换为1后 得到一串二进制数值 ...
- go语言循环变量
阅读go语言圣经第五章第六节介绍到了捕获迭代变量 package main import ( "fmt" ) func main() { var lis []func() for ...
- django中的几种返回模版的方式
redirect方法-----(重定向) # 首先导入redirect方法, from django.shortcuts import redirect 在函数中写一个返回值 return redir ...
- std::async的使用总结
C++98标准中并没有线程库的存在,直到C++11中才终于提供了多线程的标准库,提供了管理线程.保护共享数据.线程间同步操作.原子操作等类.多线程库对应的头文件是#include <thread ...
- Py-面向对象,组合,继承
面向对象 只有特定对象能使用特定的几个方法对象=特征+动作 def dog(name,gender,type): #狗的动作 def jiao(dog): print('一条狗%s,汪汪汪' %dog ...
- nfs samba文件共享服务
(注意:实验之前强关闭selinux和防火墙) 一丶nfs ① 1.服务端 启动服务 systemctl start nfs.service 配置文件 vim /etc/exports share ...
- testng学习笔记-- beforesuit和aftersuit
一.定义 测试套件,主要关注执行顺序 套件:suit可以包含多个class 二.代码标签 三.运行结果
- rehash (重新散列)
rehash - Redis 设计与实现 http://redisbook.com/preview/dict/rehashing.html
- Group by 优化
一个标准的 Group by 语句包含排序.分组.聚合函数,比如 select a,count(*) from t group by a ; 这个语句默认使用 a 进行排序.如果 a 列没有索引,那 ...