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

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. 学习笔记(10)- 智能会话框架rasa

    https://rasa.com/ 阿里用过这个,贝壳也在用这个. 优点: 有中文版本(https://github.com/crownpku/rasa_nlu_chi): 2018年发布,文档多,业 ...

  2. 什么是Nib文件

    Nib文件是一种特殊类型的资源文件,它用于保存iPhone OS或Mac OS X应用程序的用户接口.Nib文件是Interface Builder文档.通常您会使用Interface Builder ...

  3. Django 执行 manage 命令方式

    本人使用的Pycharm作为开发工具,可以在顶部菜单栏的Tools->Run manage.py Task直接打开manager 命令控制台 打开后在底部会有命令窗口: 或者,也可以在Pytho ...

  4. Python 基础之返回值与函数使用与局部变量和全局变量locals() 和 globals()

    一.函数的返回值 return return: 自定义返回值,返回到哪里? 返回到函数的[调用处]1.return 后面可以跟上六个标准数据类型,除此之外,可以跟上 类对象,函数,如果不写return ...

  5. Java 实现简单的人机猜拳游戏

    import java.util.Scanner; import java.util.Random; public class TestGuess{ public static void main(S ...

  6. 144、Java链表之定义一个Node类并输出

    01.代码如下: package TIANPAN; class Node { // 每一个链表实际上就是由多个节点组成的 private String data; // 要保存的数据 private ...

  7. 把PHP大牛记下来,方便以后关注

    本帖最后由 fish_study 于 2014-12-31 00:18 编辑 五四陈科学院博主54chen(陈臻),哥学社创始人,前人人网分布式存储nuclear研发人员,现关注erlang.hado ...

  8. 吴裕雄--天生自然JAVAIO操作学习笔记:投票程序

    public class ExecDemo{ public static void main(String args[]){ new Operate() ; } }; import java.io.B ...

  9. python deepcopy的替代方案

    from copy import deepcopy import marshal import timeit from multidict import CIMultiDict def test_de ...

  10. Linux --xrandr command

    Source: https://www.x.org/archive/current/doc/man/man1/xrandr.1.xhtml https://blog.csdn.net/syh_486_ ...