Codeforces Round #618 (Div.1) (Div.2) (CF1299) (CF1300)

A:读进来就把0搞成1,S!=0就直接输出,S=0判一下有没有不是-1的,有不是-1的就+1否则+2。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 #define it register int
 5 #define ct const int
 6 #define il inline
 7 using namespace std;
 8 const int N=100005;
 9 int n,T,a[N];
10 namespace io{
11     il char nc(){
12         static char buf[100000],*p1=buf,*p2=buf;
13         return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
14     }
15     template <class I>
16     il void fr(I &num){
17         num=0;register char c=nc();it p=1;
18         while(c<‘0‘||c>‘9‘) c==‘-‘?p=-1,c=nc():c=nc();
19         while(c>=‘0‘&&c<=‘9‘) num=num*10+c-‘0‘,c=nc();
20         num*=p;
21     }
22 }
23 using io ::fr;
24 int main(){
25     fr(T);
26     while(T--){
27         fr(n);it ans=0,s=0;
28         for(it i=1;i<=n;++i){
29             fr(a[i]);
30             if(!a[i]) ++ans,a[i]=1;
31             s+=a[i];
32         }
33         if(s){printf("%d\n",ans);continue;}
34         it flag=2;
35         for(it i=1;i<=n;++i)
36             if(a[i]!=-1){flag=1;break;}
37         printf("%d\n",ans+flag);
38     }
39     return 0;
40 }

A

B:我甚至没怎么看懂题就大力猜结论然后过了。。肯定是排序后两个中间的数相减啊。。因为在它们前面和后面的数可以把它们推到新的两边数组的中位数上。。。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 #define it register int
 5 #define ct const int
 6 #define il inline
 7 using namespace std;
 8 const int N=1000005;
 9 int a[N],n,T;
10 namespace io{
11     il char nc(){
12         static char buf[100000],*p1=buf,*p2=buf;
13         return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
14     }
15     template <class I>
16     il void fr(I &num){
17         num=0;register char c=nc();it p=1;
18         while(c<‘0‘||c>‘9‘) c==‘-‘?p=-1,c=nc():c=nc();
19         while(c>=‘0‘&&c<=‘9‘) num=num*10+c-‘0‘,c=nc();
20         num*=p;
21     }
22 }
23 using io ::fr;
24 int main(){
25     it T;fr(T);
26     while(T--){
27         fr(n),n<<=1;
28         for(it i=1;i<=n;++i) fr(a[i]);
29         std::sort(a+1,a+1+n);
30         printf("%d\n",a[n/2+1]-a[n/2]);
31     }
32     return 0;
33 }

B

C:看错数据范围交了十几发。。一个结论是f(f(a,b),c)=f(a,b|c),然后f(a,b)就是把a,b共有的位置减掉。所以找到一个ai,使得它的最高位1只有它拥有,把它扔到前面去,其他的不用排。。坑点是要判断这样的ai有没有。。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 #define it register int
 5 #define ct const int
 6 #define il inline
 7 using namespace std;
 8 const int N=1000005;
 9 int ans,ID,id,a[N],n,b[N],cn[N];
10 namespace io{
11     il char nc(){
12         static char buf[100000],*p1=buf,*p2=buf;
13         return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
14     }
15     template <class I>
16     il void fr(I &num){
17         num=0;register char c=nc();it p=1;
18         while(c<‘0‘||c>‘9‘) c==‘-‘?p=-1,c=nc():c=nc();
19         while(c>=‘0‘&&c<=‘9‘) num=num*10+c-‘0‘,c=nc();
20         num*=p;
21     }
22 }
23 using io ::fr;
24 il void fj(it x){
25     for(it i=31;~i;--i)
26         if(x&(1<<i)) ++cn[i];
27 }
28 int main(){
29     fr(n);
30     for(it i=1;i<=n;++i) fr(a[i]),++ID,fj(a[i]);
31     ID=0;
32     for(it i=31;~i;--i)if(cn[i]==1){ID=1<<i;break;}
33     for(it i=1;i<=n;++i) if((a[i]&ID)==ID){id=i;break;}
34     if(id) printf("%d ",a[id]);
35     for(it i=1;i<=n;++i) if(i^id) printf("%d ",a[i]);
36     return 0;
37 }  

C

D:

萌神:你为什么只做了ABCE?

我:因为我网速慢看不到D的图片~

萌神:D就是判断是不是中心对称图形啊

我:这么**?

萌神:但你得推出来这一步~

(其实萌神就是疯狂暗示我:你这个菜鸡哪里推得出来!)

 1 #include<stdio.h>
 2 #define it register int
 3 #define il inline
 4 const int N=1000005;
 5 int x[N],y[N],n,a,b;
 6 namespace io{
 7     il char nc(){
 8         static char buf[100000],*p1=buf,*p2=buf;
 9         return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
10     }
11     template <class I>
12     il void fr(I &num){
13         num=0;register char c=nc();it p=1;
14         while(c<‘0‘||c>‘9‘) c==‘-‘?p=-1,c=nc():c=nc();
15         while(c>=‘0‘&&c<=‘9‘) num=num*10+c-‘0‘,c=nc();
16         num*=p;
17     }
18 }
19 using io ::fr;
20 int main(){
21     fr(n);
22     if(n&1) return puts("NO"),0;
23     for(it i=1;i<=n;++i) fr(x[i]),fr(y[i]);
24     n>>=1,a=x[1]+x[n+1],b=y[1]+y[n+1];
25     for(it i=2;i<=n;++i)
26         if(x[i]+x[n+i]!=a||y[i]+y[n+i]!=b) return puts("NO"),0;
27     puts("YES");
28     return 0;
29 }

D

E:贪心。记录一下这一层的和以及个数,尽量让前面小的更优。(我记得yg说Div1的贪心难得一批?yg出来挨打!)

代码暂时不贴(怕fst身败名裂)

原文地址:https://www.cnblogs.com/Kylin-xy/p/tijieCF1300.html

时间: 2024-10-17 14:36:12

Codeforces Round #618 (Div.1) (Div.2) (CF1299) (CF1300)的相关文章

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二场CF! 成绩:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 题目:Educational Codeforces Round 57 (Rated for Div. 2) 错题题解: D. Easy Problem E. The Top Scorer F. Inversion Expectation G. Lucky Tickets 原文地址:https://www.cnblogs.com/xht37/p/10198321.html

Educational Codeforces Round 58 (Rated for Div. 2)(待更新)

get人生第七场CF! 成绩:(exACM) rank AC3/7 Penalty104 rating() 题目:Educational Codeforces Round 58 (Rated for Div. 2) 错题题解: C. Division and Union 原文地址:https://www.cnblogs.com/xht37/p/10260260.html

Educational Codeforces Round 59 (Rated for Div. 2) DE题解

Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contest/1107/problem/D 题意: 给出一个n*(n/4)的矩阵,这个矩阵原本是一些01矩阵,但是现在四个四个储存进二进制里面,现在给出的矩阵为0~9以及A~F,表示0~15. 然后问这个矩阵能否压缩为一个(n/x)*(n/x)的矩阵,满足原矩阵中大小为x*x的子矩阵所有数都相等(所有子矩阵构

Codeforces Round #503 (by SIS, Div. 2)

Codeforces Round #503 (by SIS, Div. 2) https://codeforces.com/contest/1020 A 1 #include <iostream> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 #include <cstdio> 6 #include <cstdlib> 7 #include <s

Educational Codeforces Round 62 (Rated for Div. 2)

layout: post title: Educational Codeforces Round 62 (Rated for Div. 2) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces - dp --- " target="_blank" style="font-size:24px;">传送门 D - Minimum Triangulat

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks