这一场涨了不少,题也比较偏思维,正好适合我

A. Non-zero

我们记录这些数字的总和sum,并且记录0的个数zero,显然答案应该是这些0的个数,注意如果sum+zero==0的话答案要额外加一(因为总和不能是0)

    #include<bits/stdc++.h>
#define LL long long
#define maxn 100010
#define x first
#define y second
using namespace std; typedef pair<int, int> pii; int a[maxn]; int main(){
int T;
cin >> T;
while(T--){
int n, sum = ;
int z = ;
cin >> n;
for(int i = ; i < n; ++i){
cin >> a[i];
sum = sum + a[i];
if(a[i] == ){
z++;
}
}
int ans = ;
if(sum == ){
ans = ;
sum++;
}
if(z != ){
ans = max(ans, z);
if(sum == ){
sum = sum + ans - ;
}
else{
sum = sum + ans;
}
}
if(sum == ){
ans++;
}
cout << ans << endl;
}
return ;
}

B. Assigning to Classes

要使得两组的中位数相差最小,很显然,如果把两组表示为G1和G2,那么如果G1的中位数更靠前,那么G2的中位数一定更靠后,那么易得当这俩中位数靠的最近的时候相差最小,此时G1跟G2的中位数应该在数组的中间,直接排序输出数组中间的差值便是答案

    #include<bits/stdc++.h>
#define LL long long
#define maxn 100010
#define inf 0x3f3f3f3f
#define x first
#define y second
using namespace std; typedef pair<int, int> pii; int a[maxn << ]; int main(){
int T;
cin >> T;
while(T--){
int n;
cin >> n;
for(int i = ; i < * n; ++i){
cin >> a[i];
}
sort(a, a + * n);
int n1, n2;
if(n % ){
cout << a[n] - a[n - ] << endl;
}
else{
cout << a[n] - a[n - ] << endl;
}
}
return ;
}

C. Anu Has a Function

我们考虑下这一组式子,对于f(a, b)=(a|b)-b函数的结果c的每一二进制位,如果这一位上b是1,那么容易知道c这一位一定是0,否则c这一位是看a这一位是否为1,很显然,c的二进制上为1的位一定是a这一位为1,b这一位为0的地方。所以推广到很多个b,就是a这一位为1,很多个b那一位全是0的时候,答案这一位才是0,取最大值就行了,我的处理方式还是比较简单的。

    #include<bits/stdc++.h>
#define LL long long
#define maxn 100010
#define inf 0x3f3f3f3f
#define x first
#define y second
using namespace std; typedef pair<int, int> pii; int a[maxn]; int bit[]; void _in(int num){
int now = ;
while(num){
if(num & ){
bit[now]++;
}
num = num >> ;
now++;
}
} int _out(int num){
int now = , ret = ;
while(num){
if(num & && bit[now] == ){
ret = ret + ( << now);
}
num = num >> ;
now++;
}
return ret;
} int main(){
int n;
cin >> n;
memset(bit, , sizeof bit);
for(int i = ; i < n; ++i){
cin >> a[i];
_in(a[i]);
}
int ma = , no = -;
for(int i = ; i < n; ++i){
if(_out(a[i]) > ma){
ma = _out(a[i]);
no = i;
}
}
if(no >= ){
cout << a[no] << " ";
}
for(int i = ; i < n; ++i){
if(i != no){
cout << a[i] << " ";
}
}
cout << endl;
return ;
}

D. Aerodynamic

题意挺麻烦的,但是结论却很简单,必须是中心对称的偶数边数的多边形,我的处理方式居然没被hack,神奇

    #include<bits/stdc++.h>
#define LL long long
#define maxn 100010
#define inf 0x3f3f3f3f
#define x first
#define y second
using namespace std; typedef pair<double, double> pdd; pdd a[maxn]; pdd b[maxn]; int main(){
int n;
cin >> n;
for(int i = ; i < n; ++i){
cin >> a[i].x >> a[i].y;
if(i > ){
b[i].x = a[i].x - a[i - ].x;
b[i].y = a[i].y - a[i - ].y;
}
}
b[].x = a[].x - a[n - ].x;
b[].y = a[].y - a[n - ].y;
sort(b, b + n);
if(n % ){
cout << "NO" << endl;
return ;
}
bool ans = true;
for(int i = ; i < n; ++i){
if(b[i].x + b[n - i - ].x != || b[i].y + b[n - i - ].y != ){
ans = false;
}
}
cout << (ans ? "YES" : "NO") << endl;
return ;
}

E. Water Balance

最后这个题听学长说是单调栈,还是比较简单明了的写法,但是我没写出来,可惜了

注意这个题取12位小数会WA,一定要取8位小数

这一场排到了576名,rating到了1700+,但是如果没有傻卵错误其实还可以再往前排一点,希望再打几场能上紫名 。

Codeforces Round #618 (Div. 2) 小号上紫之路的更多相关文章

  1. Codeforces Round #618 (Div. 2)

    题库链接 https://codeforces.ml/contest/1300 A. Non-zero 一个数组,每次操作可以给某个数加1,让这个数组的积和和不为0的最小操作数 显然如果有0的话,必须 ...

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

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

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

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

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

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

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

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

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

  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. WebVR大潮来袭时,前端开发能做些什么

    WebVR大潮来袭时,前端开发能做些什么?     WebVR即web + VR的体验方式,我们可以戴着头显享受沉浸式的网页,新的API标准让我们可以使用js语言来开发.本文将介绍如何快速开发一个We ...

  2. ch8 让div居中--使用外边距

    假设有一个布局,希望让其中的容器div在屏幕上水平居中,则只需要定义div的宽度,然后将水平外边距设置为auto <body> <div class="wrapper&qu ...

  3. python使用pip安装库时出现timeout或者速度慢

    豆瓣:https://pypi.doubanio.com/simple/ pip3 install -i https://pypi.doubanio.com/simple/ selenium easy ...

  4. KMP(模板)

    kmp算法是解决单模匹配问题的算法,难点在于求next[]数组 求next[]数组:对于模板串的所有前缀子串的最长公共前后缀的长度,就是next[]数组的值 eg:主串为cbbbaababac  子串 ...

  5. SpingBoot学习(一)

    一.概述 Spring Boot是为了简化Spring应用的创建.运行.调试.部署等而出现的,使用它可以做到专注于Spring应用的开发,而无需过多关注XML的配置. 简单来说,它提供了一堆依赖打包, ...

  6. VirtualBox安装Debian

    1.下载Debian的dvd1,按照http://www.jb51.net/os/85858.html网上教程安装Debian 1.1.我创建了20G的虚拟磁盘,分区的时候我分了3个区,2G交换空间, ...

  7. 自定义sort排序

    java的sort自定义: 1.排序对象必须是封装类而不能是基本数据类型: 2.调用Arrays.sort(array, left, right, cmp)进行排序,array为数组,left.rig ...

  8. 092、Java中String类之字符串内容比较

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  9. eot文件

    *.eot文件 是一种压缩字库,目的是解决在网页中嵌入特殊字体的难题2.在网页中嵌入的字体只能是 OpenType 类型,其他类型的字体只有转换成 OpenType 类型(eot格式)的字体才能在网页 ...

  10. (实例)Linux 内核添加exfat驱动

    背景: 由于exfat是常用的文件系统格式,而Linux由于版权的问题,没有在官方中添加有关的驱动. 但是 微软也同意开源了,所以比较新的 Linux 会支持这一块. 为了支持exfat的驱动,我们需 ...