Codeforces Round #618 (Div. 2)
题库链接
https://codeforces.ml/contest/1300
A. Non-zero
一个数组,每次操作可以给某个数加1,让这个数组的积和和不为0的最小操作数
显然如果有0的话,必须操作一次,最后如果和还是为0的话,再操作一次
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m;
int a[maxn];
signed main()
{
#ifdef ONLINE_JUDGE
#else
freopen("data.in", "r", stdin);
#endif
int T;
cin>>T;
while(T--)
{
cin>>n;
int sum = 0;
int ans = 0;
for(int i = 1; i <= n; i++)
{
cin>>a[i];
if(a[i] == 0)
{
ans++;
a[i] = 1;
}
sum += a[i];
}
if(sum == 0) ans++;
cout<<ans<<endl;
}
return 0;
}
B. Assigning to Classes
有一个数组有2*n个元素,要分成两个数组,每个数组必须是奇数个元素,求两个数组的中位数之差的最小值
假设左边的中位数会小于右边的中位数,显然,左边越大越好,右边越小越好,大能大到什么程度呢?最大就是原数组的中位数
所以答案就是原数组的中间两个数的差值
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m;
int a[maxn];
signed main()
{
#ifdef ONLINE_JUDGE
#else
freopen("data.in", "r", stdin);
#endif
int T;
cin>>T;
while(T--)
{
cin>>n;
for(int i = 1; i <= 2*n; i++)
{
cin>>a[i];
}
sort(a+1,a+1+2*n);
cout<<abs(a[n]-a[n+1])<<endl;
}
return 0;
}
C. Anu Has a Function
\(f(x, y) = (x | y) - y\)
要求重新排列数组,使得\(f(f(\dots f(f(a_1, a_2), a_3), \dots a_{n-1}), a_n)\)最大
我们先看f函数,x或y减去y,把它拆分成二进制,对于某一位,如果x,y都是1,f(x, y)之后x的这一位会被减去
如果x是1,y是0,或者x是0,y是1,那么x的这一位不变
所以我们只需要求出某一位只有x是1,其余数组元素都是0的最高位,让它在最前面就好了,其它元素随便排列
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m;
int a[maxn];
int vis[33];
int b[33];
signed main()
{
#ifdef ONLINE_JUDGE
#else
freopen("data.in", "r", stdin);
#endif
cin>>n;
for(int i = 1; i <= n; i++)
{
cin>>a[i];
for(int j = 30; j >= 0; j--)
{
if((1<<j)&a[i])
{
vis[j]++;
b[j] = i;
}
}
}
int ans = 1;
for(int i = 0; i <= 30; i++)
{
if(vis[i] == 1) ans = b[i];
}
cout<<a[ans]<<' ';
for(int i = 1; i <= n; i++)
{
if(i != ans) cout<<a[i]<<' ';
}
return 0;
}
D. Aerodynamic
就是问你是否中心对称
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m;
vector<pii> v;
signed main()
{
#ifdef ONLINE_JUDGE
#else
freopen("data.in", "r", stdin);
#endif
cin>>n;
v.push_back({0,0});
for(int i = 1,x,y; i <= n; i++)
{
cin>>x>>y;
v.push_back({x,y});
}
if(n%2) {puts("NO");return 0;}
int t = n/2;
double midx = (v[1].first + v[t+1].first)*1.0/2;
double midy = (v[1].second + v[t+1].second)*1.0/2;
for(int i = 2; i <= t; i++)
{
double tmpx = (v[i].first + v[t+i].first)*1.0/2;
double tmpy = (v[i].second + v[t+i].second)*1.0/2;
if(midx != tmpx || midy != tmpy)
{
puts("NO");return 0;
}
}
puts("YES");
return 0;
}
E. Water Balance
有n个水桶,每次可以选择一些区间,使得区间内的水桶的水量等于区间水量之和除以区间长度
问你可以得到的水量的字典序的最小是什么
单调栈可以做,凸包也可以做,凸包我不会,说一下单调栈的做法
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 1001110;
const int M = 1e9+7;
int n,m;
int a[maxn];
int sa[maxn];
int la[maxn];
signed main()
{
#ifdef ONLINE_JUDGE
#else
freopen("data.in", "r", stdin);
#endif
cin>>n;
for(int i = 1; i <= n; i++)
{
cin>>a[i];
}
int top = 0;
for(int i = 1; i <= n; i++)
{
int tsa = a[i],tla = 1;
for(;top && sa[top]*tla >= tsa*la[top]; top--)
{
tsa += sa[top];
tla += la[top];
}
++top;
sa[top] = tsa;
la[top] = tla;
}
for(int i = 1,cur = 1; i <= top; i++,cur += la[top])
{
for(int j = cur;j < cur + la[i]; j++)
{
printf("%.9f\n",sa[i]*1.0/la[i]);
}
}
return 0;
}
Codeforces Round #618 (Div. 2)的更多相关文章
- Codeforces Round #618 (Div. 1)C(贪心)
把所有数看作N块,后面的块比前面的块小的话就合并,这个过程可能会有很多次,因为后面合并后会把前面的块均摊地更小,可能会影响更前面地块,像是多米诺骨牌效应,从后向前推 #define HAVE_STRU ...
- Codeforces Round #618 (Div. 1)B(几何,观察规律)
观察猜测这个图形是中心对称图形是则YES,否则NO #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace ...
- Codeforces Round #618 (Div. 1)A(观察规律)
实际上函数值为x&(-y) 答案仅和第一个数字放谁有关 #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using na ...
- Codeforces Round #618 (Div. 2)A. Non-zero
Guy-Manuel and Thomas have an array aa of nn integers [a1,a2,…,an ]. In one step they can add 11 to ...
- Codeforces Round #618 (Div. 2)C. Anu Has a Function
Anu has created her own function ff : f(x,y)=(x|y)−y where || denotes the bitwise OR operation. For ...
- Codeforces Round #618 (Div. 2) 小号上紫之路
这一场涨了不少,题也比较偏思维,正好适合我 A. Non-zero 我们记录这些数字的总和sum,并且记录0的个数zero,显然答案应该是这些0的个数,注意如果sum+zero==0的话答案要额外加一 ...
- [CF百场计划]#2 Codeforces Round #618 (Div. 2)
A. Non-zero Description: Guy-Manuel and Thomas have an array \(a\) of \(n\) integers [\(a_1, a_2, \d ...
- Codeforces Round #618 (Div. 2)-B. Assigning to Classes
Reminder: the median of the array [a1,a2,-,a2k+1] of odd number of elements is defined as follows: l ...
- Codeforces Round #618 (Div. 2)-Non-zero
Guy-Manuel and Thomas have an array a of n integers [a1,a2,-,an]. In one step they can add 1 to any ...
随机推荐
- [Linux实践] macOS平台Homebrew更新brew update卡死,完美解决
[Linux实践] macOS 平台 Homebrew 更新 brew update 卡死,完美解决 版本2020.01.05 摘要: 使用brew install [软件包]安装软件包时,卡在Upd ...
- HTTP请求中的GET-POST方式
目录 一.前言部分(概念) 二.对比 GET 与 POST 二者最大的差异 GET 与 POST 请求本质上并无区别 深层了解:POST 请求产生两个数据包? 三.两种请求方式如何灵活使用? 四.常见 ...
- cannot open git-upload-pack,cannot open git-receive-pack,Can't connect to any URI错误解决方法eclipse
cannot open git-upload-pack,cannot open git-receive-pack,Can't connect to any URI错误解决方法eclipse 解决ecl ...
- 通过ArcGIS将数据存储到SQL Server2012中
一.软件安装: ARCGIS 10.3安装 SQLserver2012安装 ARCGIS 10.3 安装(注意ARCGIS10.3并不用安装配置ARCSDE). https://wenku.baidu ...
- redis 支持事务
pipe = conn.pipeline(transaction=True) pipe.multi() pipe.set(') pipe.hset('k3','n1',666) pipe.lpush( ...
- ORM基础1
1.增删改查 .models.类.object.all() 获取所有对象->select * from 表 2.models.类.object.get(id=1) 获取id为1的对象->s ...
- Postman post csrf_token
1.填入代码 var csrf_token = postman.getResponseCookie("csrftoken").value postman.clearGlobalVa ...
- Uva1014:Remember the Word
Neal is very curious about combinatorial problems, and now here comes a problem about words. Knowing ...
- 深入浅出WPF笔记
数据层(Database,Oracle等) 业务逻辑层(Service,Data Access Layer,WCF) 表示层(WPF,Win Form,ASP.net,Silverlight) [WP ...
- xlwings excel(三)
App相当于Excel程序,Book相当于工作簿.N个Excel程序则由apps表示,N个工作簿由books表示. 对工作簿的操作 #导入xlwings模块 import xlwings as xw ...