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 ...
随机推荐
- No value specified for Date
现象 使用BeanUtils复制对象属性,结果抛出No value specified for Date异常. 原因 是数据源orig有一个参数是java.util.Date类型,没有初始化值,调用了 ...
- Dart对象和类
/* 面向对象编程(OOP)的三个基本特征是:封装.继承.多态 封装:封装是对象和类概念的主要特性.封装,把客观事物封装成抽象的类,并且把自己的部分属性和方法提供给其他对象调用, 而一部分属性和方法则 ...
- openresty开发系列2--nginx的简单安装,正向、反向代理及常用命令和信号控制介绍
openresty开发系列2--nginx的简单安装,正向.反向代理及常用命令和信号控制介绍 一.nginx的安装下载及编译安装1.Nginx下载:nginx-1.13.0.tar.gz,下载到:/u ...
- 设计input搜索框提示文字点击消失的效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- SftpUtil FTP文件上传
package ftputil; import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream; ...
- Apache调优(一)
(1).Apache和Tomcat的关系 Apache HTTPD Server与Apache Tomcat同属于Apache的开源项目.两个都可以单独作为web server使用,但是又都有各自的特 ...
- 【shell比较字符串】
if [ 'AAA' = 'ABC' ]; then echo "the same" else echo "not the same" fi shell比较字符 ...
- CSS3 Filter特效
CSS3 filter和IE的filter完全是两样东东. Filters主要是运用在图片上,以实现一些特效.(尽管他们也能运用于video上),不过我们在些只来讨论图片上的运用. 语法 elm { ...
- 【JQuery插件】扑克正反面翻牌效果
里面有两个demo,支持X横向和Y纵向翻转两个效果. 对元素的布局有一定的讲究,需要分析一下demo的css. 默认翻转速度为80,不要大于100ms. <!DOCTYPE> <ht ...
- 使用Maven为SpringBoot项目打包
一.maven通过命令行打jar包 进入项目目录,执行如下命令: mvn -Dmaven.test.skip -U clean package 发现报如下错误: [ERROR] Failed to e ...