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

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. 【PAT甲级】1026 Table Tennis (30 分)(结构体排序,trick较多)

    题意: 输入一个正整数N(<=10000),表示客户(对)的大小,接着输入N行数据,每行包括一对顾客到场的时间,想要玩的时间,以及是否是VIP客户.接下来输入两个正整数K,M(K<=100 ...

  2. 「POJ3613」Cow Relays

    「POJ3613」Cow Relays 传送门 就一个思想:\(N\) 遍 \(\text{Floyd}\) 求出经过 \(N\) 个点的最短路 看一眼数据范围,想到离散化+矩阵快速幂 代码: #in ...

  3. CSP-S 2019 初赛游记

    Day 0 上午考了一套毒瘤的数据结构题,考的我心态爆炸SB出题人 晚上考了一套初赛模拟,只考1h,然后我91分,感觉初赛完全没问题? 回寝室后一直在忙活,整理东西什么的,居然将近12点睡? Day ...

  4. python的沙盒环境--virtualenv

      VirtualEnv用于在一台机器上创建多个独立的python运行环境,VirtualEnvWrapper为前者提供了一些便利的命令行上的封装. 使用 VirtualEnv 的理由: 隔离项目之间 ...

  5. Abstract Data Type

  6. 洛谷 P2891 [USACO07OPEN]吃饭Dining

    裸的最大流. #include <cstdio> #include <cstring> #include <queue> const int MAXN = 4e3 ...

  7. 这两天的pwn学习总结

    总是一会儿切到那里,一会儿切到那里,要明确一条主线,就是buu的题,而不是按着什么视频教程还有linux和python教程去学习.那样效率比较低. 一切为了写wp为本,不胡乱点击就是提高效率的最好办法 ...

  8. android sqlite 图片保存和读出 用流 转字节码

    原文:http://blog.sina.com.cn/s/blog_8cfbb99201012oqn.html package com.yiyiweixiao; import android.cont ...

  9. MyBatis Dao层的编写

    传统的dao层编写 以前编写dao层,先新建一个包com.chy.dao,再写接口StudentDao: public interface StudentDao { public void inser ...

  10. 5.5 Nginx 负载均衡

    ip_hash 语法:ip_hash 默认值:none 使用字段:upstream 这个指令将基于客户端连接的IP地址来分发请求.哈希的关键字是客户端的C类网络地址,这个功能将保证这个客户端请求总是被 ...