Educational Codeforces Round 61 (Div.2)
A.(c1=0&&c3>0)||(c1!=c4)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; int c1,c2,c3,c4; int main(){
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
scanf("%d%d%d%d",&c1,&c2,&c3,&c4);
if ((!c1 && c3) || c1!=c4) puts(""); else puts("");
return ;
}
A
B.每次免费的显然应该是第n-q+1大的那个。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=;
int n,m,x,a[N];
ll sm; int main(){
scanf("%d",&n);
rep(i,,n) scanf("%d",&a[i]),sm+=a[i];
sort(a+,a+n+); scanf("%d",&m);
rep(i,,m) scanf("%d",&x),cout<<sm-a[n-x+]<<endl;
return ;
}
B
C.正难则反,先计算所有区间的并集sm,再计算最少要使多长区间不被覆盖ans,答案即sm-ans。
考虑枚举区间i,j,那么不涂这两个区间会使b[i]+b[j]+c[i][j]的区间不被覆盖。其中b[i]为只能由第i个区间覆盖的区间长度,c[i][j]为只能被i,j两个区间覆盖的区间长度。先O(nq)预处理出b,c,再O(q^2)计算答案即可。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=;
int n,m,l,r,sm,ans,x[N],y[N],b[N],mp[N][N]; int main(){
scanf("%d%d",&n,&m); ans=n+;
rep(i,,m){
scanf("%d%d",&l,&r);
rep(j,l,r){
if (y[j]) x[j]=y[j]=-;
if (x[j] && !y[j]) y[j]=i;
if (!x[j]) x[j]=i;
}
}
rep(i,,n){
if (x[i]) sm++;
if (x[i]> && !y[i]) b[x[i]]++;
if (x[i]> && y[i]>) mp[x[i]][y[i]]++,mp[y[i]][x[i]]++;
}
rep(i,,m) rep(j,,m) if (i!=j) ans=min(ans,b[i]+b[j]+mp[i][j]);
printf("%d\n",sm-ans);
return ;
}
C
D.二分答案,每次找到最先降到0以下的那个同学充电。
#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=;
int n,k;
ll mx,a[N],b[N];
struct P{ ll a,b,r; };
bool operator <(const P &a,const P &b){ return a.r>b.r; }
priority_queue<P>Q; bool chk(ll mid){
while (!Q.empty()) Q.pop();
rep(i,,n) Q.push((P){a[i],b[i],a[i]/b[i]});
rep(t,,k){
P x=Q.top(); Q.pop();
if (x.a/x.b+<t) return ;
if (x.a/x.b+>=k) return ;
Q.push((P){x.a+mid,x.b,(x.a+mid)/x.b});
}
return ;
} int main(){
ios::sync_with_stdio();
cin>>n>>k;
rep(i,,n) cin>>a[i];
rep(i,,n) cin>>b[i],mx=max(mx,b[i]);
ll L=,R=(k-)*mx+;
while (L<R){
ll mid=(L+R)>>;
if (chk(mid)) R=mid; else L=mid+;
}
if (L>=(k-)*mx+) puts("-1"); else cout<<L<<endl;
return ;
}
D
Educational Codeforces Round 61 (Div.2)的更多相关文章
- Educational Codeforces Round 61
Educational Codeforces Round 61 今早刚刚说我适合打pikmike出的EDU 然后我就挂了 A 不管 B 不管 C 这道题到快结束了才调出来 大概就是\(n^2\)枚举不 ...
- Educational Codeforces Round 84 (Div. 2)
Educational Codeforces Round 84 (Div. 2) 读题读题读题+脑筋急转弯 = =. A. Sum of Odd Integers 奇奇为奇,奇偶为偶,所以n,k奇偶性 ...
- Educational Codeforces Round 61 (Rated for Div. 2) D,F题解
D. Stressful Training 题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有n台电脑,每台电脑都有初始电量ai,也有一个 ...
- Educational Codeforces Round 61 (Rated for Div. 2) E 多重背包优化
https://codeforces.com/contest/1132/problem/E 题意 有8种物品,重量是1~8,每种数量是\(cnt[i]\)(1e16),问容量为W(1e18)的背包最多 ...
- Educational Codeforces Round 61 (Rated for Div. 2)-C. Painting the Fence 前缀和优化
题意就是给出多个区间,要求去掉两个区间,使得剩下的区间覆盖范围最大. 当然比赛的时候还是没能做出来,不得不佩服大佬的各种姿势. 当时我想的是用线段树维护区间和,然后用单点判0,维护区间间断个数.然后打 ...
- Educational Codeforces Round 61 (Rated for Div. 2)
A. Regular Bracket Sequence 题意:给出四种括号的数量 (( )) () )( 问是否可以组成合法的序列(只能排序不能插在另外一个的中间) 思路: 条件一:一个或 n个) ...
- Educational Codeforces Round 61 (Rated for Div. 2) E. Knapsack
非常经典的dp题,因为1至8的最大公约数是840,任何一个数的和中840的倍数都是可以放在一起算的, 所以我只需要统计840*8的值(每个数字(1-8)的sum%840的总和),剩下都是840的倍数 ...
- Educational Codeforces Round 61 (Rated for Div. 2) G(线段树,单调栈)
#include<bits/stdc++.h>using namespace std;int st[1000007];int top;int s[1000007],t[1000007];i ...
- Educational Codeforces Round 61 (Rated for Div. 2)F(区间DP,思维,枚举)
#include<bits/stdc++.h>typedef long long ll;const int inf=0x3f3f3f3f;using namespace std;char ...
随机推荐
- linux: E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
今天在使用ubuntu执行下列指令的时候出现了错误: sudo apt-get update 解决办法: 输入以下命令: sudo rm /var/cache/apt/archives/lock su ...
- centos6环境远程执行shell脚本报错not a valid identifier的问题处理
# 通过jenkins的apache用户rsync同步php代码到远程服务器报错如下: SSH: EXEC: STDOUT/STDERR from command [/bin/sh /usr/loca ...
- Spring Cloud微服务安全实战- 2-1 环境安装
下面这些.后续随着讲课逐步再去安装. 2019年1月开始 jdk是收费的 找jdk最后一个免费版本 8u192这是jdk1.8最后的一个免费版本 STS spring提供的ide可以方便的开发spri ...
- 【composer】 PHP composer 镜像地址更换
如果你使用的是 laravel-china.org 得 composer 镜像.那么近期执行更新时候就会报错: 莫慌,这是因为 laravel-china.org 已经停止了对composer得更新. ...
- Python subprocess中的run方法
调用subprocess的推荐方法是对于它可以处理的所有使用场景都使用run()函数. run()函数是在Python 3.5中添加的,如果在老版本中使用,需要下载并扩展. 扩展安装方式: $ pip ...
- Flink 在IDEA执行时的webui
不过Flink IDEA中执行的webui 需要 flink-runtime-web 包的支持 pom 如下: <dependency> <groupId>org.apache ...
- WinForm,在另一个线程中更新Form中的数据(转)
Form本身有线程,但对于一些耗时的操作,我们不希望在Form的线程中进行,因为会导致Form线程阻塞,产生假死的现象. 其他线程中操作Form中的控件,总出现“线程间操作无效: 从不是创建控件的线程 ...
- ROW_NUMBER()函数使用详解
原文地址:https://blog.csdn.net/qq_30908543/article/details/74108348 注:mysql貌似不适用,本人测试未成功,mysql实现方式可参考:ht ...
- 管道式编程(Pipeline Style programming)
受 F# 中的管道运算符和 C# 中的 LINQ 语法,管道式编程为 C# 提供了更加灵活性的功能性编程.通过使用 扩展函数 可以将多个功能连接起来构建成一个管道. 前言 在 C# 编程中,管道式编程 ...
- 仔细看参数--NGINX之tcp_nodelay
一.知识准备 ● 在nginx优化中有个经常需要设置的参数,tcp_nodelay ● 该参数最核心的功能,就是把小包组成成大包,提高带宽利用率也就是著名的nagle算法 ● tcp协议中,有一个现象 ...