题库链接

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)的更多相关文章

  1. Codeforces Round #618 (Div. 1)C(贪心)

    把所有数看作N块,后面的块比前面的块小的话就合并,这个过程可能会有很多次,因为后面合并后会把前面的块均摊地更小,可能会影响更前面地块,像是多米诺骨牌效应,从后向前推 #define HAVE_STRU ...

  2. Codeforces Round #618 (Div. 1)B(几何,观察规律)

    观察猜测这个图形是中心对称图形是则YES,否则NO #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace ...

  3. Codeforces Round #618 (Div. 1)A(观察规律)

    实际上函数值为x&(-y) 答案仅和第一个数字放谁有关 #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using na ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #618 (Div. 2) 小号上紫之路

    这一场涨了不少,题也比较偏思维,正好适合我 A. Non-zero 我们记录这些数字的总和sum,并且记录0的个数zero,显然答案应该是这些0的个数,注意如果sum+zero==0的话答案要额外加一 ...

  7. [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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 「洛谷P1231」教辅的组成 解题报告

    P1231 教辅的组成 题目背景 滚粗了的HansBug在收拾旧语文书,然而他发现了什么奇妙的东西. 题目描述 蒟蒻HansBug在一本语文书里面发现了一本答案,然而他却明明记得这书应该还包含一份练习 ...

  2. 1064 朋友数 (20 分)C语言

    如果两个整数各位数字的和是一样的,则被称为是"朋友数",而那个公共的和就是它们的"朋友证号".例如 123 和 51 就是朋友数,因为 1+2+3 = 5+1 ...

  3. 来吧,一文彻底搞懂Java中最特殊的存在——null

    没事的时候,我并不喜欢逛 P 站,而喜欢逛 programcreek 这些技术型网站,于是那天晚上,在夜深人静的时候,我就发现了一个专注基础但不容忽视的主题.比如说:Java 中的 null 到底是什 ...

  4. 论Java中的抽象类与接口

    目录 抽象类和抽象方法 定义 与普通类的区别以及注意点: 抽象类的作用 接口 定义 示例 注意 作用 最后:接口与抽象类的异同 使用场景 借鉴 抽象类和抽象方法 定义 抽象方法和抽象类都必须被abst ...

  5. DevExpress 控件用法笔记(VB)

    1.ChartControl 显示条形图 ChartControl1.Titles.Clear() ChartControl1.Series.Clear() Dim db As DataTable S ...

  6. 快速搭建一个自己的个人博客(Github Pages~二次元主题)

    前言 本次的一个布局技术都写的非常详细了,只要按着来就行,不过,先说明本次主题为二次元主题. 如果真的喜欢本主题的不妨可以试一试(==建议跟据目录来看==) 在很久很久以前.... 嘛,就在前不久我正 ...

  7. pinpoint实现告警推送至钉钉和微信群

    前言 在前面的文章中,我们学习了如何通过java实现将消息发送到钉钉.和将消息发送到微信群聊. 基于上述基础,我们今天来接入pinpoint的告警,发送到钉钉群. 实操前准备 开始之前,推荐阅读一下, ...

  8. 1、纯python编写学生信息管理系统

    1.效果图 2.python code: class studentSys(object): ''' _init_(self) 被称为类的构造函数或初始化方法, self 代表类的实例,self 在定 ...

  9. WiFi模块Demo(新手教程)图文详解模块使用教程

    本文出自APICloud官方论坛,感谢论坛版主 Mr.ZhouHeng 的分享. 第一步我们需要在开发控制台创建一个Native App应用以及添模块的准备工作: 按照下图步骤 输入完点创建完成之后 ...

  10. 谈谈Java的Collection接口

    目录 谈谈Collection 前言 Collection 方法 1.boolean add(E) 2.void clear() 3.boolean contains(Object o) 4.bool ...