传送门

好难受啊掉\(rating\)了……

\(A\ Ilya\ and\ a\ Colorful\ Walk\)

找到最后一个与第一个颜色不同的,比一下距离,然后再找到最左边和最右边与第一个颜色不同的,再和所有与第一个颜色相同的比较一下距离

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=3e5+5;
int a[N],n,mx,bg;
int main(){
// freopen("testdata.in","r",stdin);
n=read();
fp(i,1,n)a[i]=read();
fp(i,1,n)if(a[i]!=a[1]){
cmax(mx,i-1);
if(!bg)bg=i;
}
fp(i,1,n)if(a[i]==a[1])cmax(mx,abs(bg-i));
bg=0;
fd(i,n,1)if(a[i]!=a[1]&&!bg){bg=i;break;}
fp(i,1,n)if(a[i]==a[1])cmax(mx,abs(bg-i));
printf("%d\n",mx);
return 0;
}

\(B\ Alyona\ and\ a\ Narrow\ Fridge\)

首先二分答案。对于一种情况显然是\(sort\)之后从右往左两两分组最优,判一下就好了

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=1005;
int a[N],st[N],top,n,h,l,r,mid,ans;
bool ck(){
top=0;
fp(i,1,mid)st[++top]=a[i];
sort(st+1,st+1+top);
int res=0;
for(R int i=mid;i>=2;i-=2){
res+=max(st[i],st[i-1]);
if(res>h)return false;
}
if(mid&1)res+=st[1];
return res<=h;
}
int main(){
// freopen("testdata.in","r",stdin);
n=read(),h=read();
fp(i,1,n)a[i]=read();
l=1,r=n,ans=1;
while(l<=r){
mid=(l+r)>>1;
ck()?(ans=mid,l=mid+1):r=mid-1;
}
printf("%d\n",ans);
return 0;
}

\(C\ Ramesses\ and\ Corner\ Inversion\)

发现操作之后最多只会使一行或一列的偶数个格子发生变化,那么只有在\(A\)和\(B\)的行列每行每列不同格子个数都是偶数时才可行

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=505;
int A[N][N],B[N][N],r[N],c[N],n,m;
int main(){
// freopen("testdata.in","r",stdin);
n=read(),m=read();
fp(i,1,n)fp(j,1,m)A[i][j]=read();
fp(i,1,n)fp(j,1,m)B[i][j]=read();
fp(i,1,n)fp(j,1,m)if(A[i][j]!=B[i][j])++r[i],++c[j];
fp(i,1,n)if(r[i]&1)return puts("No"),0;
fp(j,1,m)if(c[j]&1)return puts("No"),0;
puts("Yes");
return 0;
}

\(D\ Frets\ On\ Fire\)

先把所有\(s_i\)升序排序,那么一行里有贡献的元素个数是\(\min\{s_{i+1}-s_i,r-l+1\}\),对于\(s_n\)来说贡献就是\(r-l+1\),所以我们记\(d_i=s_{i+1}-s_i\),\(d_n=inf\),然后\(sort\)一下,二分找到第一个\(\geq r-l+1\)的位置,前面的贡献是前缀和,后面的贡献是元素个数乘上\(r-l+1\)

//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define inf 2e18
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
ll read(){
R ll res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R ll x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]=' ';
}
const int N=1e5+5;
ll s[N],sum[N],l,r,w;int n,q,p;
int main(){
// freopen("testdata.in","r",stdin);
n=read();
fp(i,1,n)s[i]=read();
sort(s+1,s+1+n);
fp(i,1,n-1)s[i]=s[i+1]-s[i];s[n]=inf;
sort(s+1,s+1+n);
fp(i,1,n)sum[i]=sum[i-1]+s[i];
q=read();
while(q--){
l=read(),r=read(),w=r-l+1;
p=lower_bound(s+1,s+1+n,w)-s-1;
print(sum[p]+w*(n-p));
}
return Ot(),0;
}

\(E\ Pavel\ and\ Triangles\)

首先三角形只能是形如\((i,i,i)\)或者\((i,j,j)(i<j)\)

然后有个贪心,从小到大考虑,首先看看能不能和前面剩余的拼成形如\((i,j,j)\)的,然后再把所有能拼成\((i,i,i)\)的都拼了。证明并不会

//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
int n,x,las,mn;ll res;
int main(){
// freopen("testdata.in","r",stdin);
n=read();
fp(i,1,n){
x=read(),mn=min(las,x>>1),x-=(mn<<1),res+=mn,las-=mn;
res+=x/3,x%=3,las+=x;
}
printf("%I64d\n",res);
return 0;
}

剩下先咕了

Codeforces Global Round 2部分题解的更多相关文章

  1. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  2. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

  3. Codeforces Global Round 2 部分题解

    F.Niyaz and Small Degrees 挺sb的一题,为什么比赛时只过了4个呢 考虑当\(x\)固定的时候怎么做.显然可以树形DP:设\(f_{u,i=0/1}\)表示只考虑\(u\)子树 ...

  4. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  5. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  6. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  7. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  8. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  9. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

随机推荐

  1. java.lang.VerifyError: Inconsistent stackmap frames at branch target 81

    java项目中有如下代码: @RequestMapping(value = "/getMxList") @ResponseBody public Map<String, Ob ...

  2. SOAP 版本可能不匹配: 出现意外的 Envelope 命名空间 http://schemas.xmlsoap.org/wsdl/

    原错误描述:SOAP 版本可能不匹配: 出现意外的 Envelope 命名空间 http://schemas.xmlsoap.org/wsdl/.应为 http://schemas.xmlsoap.o ...

  3. js获取不到动态添加的标签的值的解决方法

    遇到了js无法获得动态添加的标签的值,百度了一番,最后自己解决了问题,但是原理现在还不怎么明确. $("input[id='txtAttValue']").each(functio ...

  4. Redis开发、管理实战

    一.数据类型 String : 字符类型 Hash: 字典类型 List: 列表 Set: 集合 Sorted set: 有序集合 二.全局Key操作 KEYS * 查看KEY支持通配符 DEL 删除 ...

  5. 23-python用BeautifulSoup用抓取a标签内所有数据

    1.获取子标签: thr_msgs = soup.find_all('div',class_=re.compile('msg'))   for i in thr_msgs:     print(i) ...

  6. 利率计算v5.0--结对--软件工程

    利率计算v5.--测试--软件工程 1.任务结对同伴: 名字:王昕明 学号: 博客地址 :http://home.cnblogs.com/u/xinmingwang/ Git : https://gi ...

  7. Ansible 笔记 (2) - Ad-hoc 命令

    先使用 ansible-doc 获取帮助文档 [root@localhost ~]# ansible-doc ping > PING (/usr/lib/python2.7/site-packa ...

  8. PHP(三)运算符、流程控制和函数初步

  9. JAVA内存管理再解

    首先我们要明白一点,我们所使用的变量就是一块一块的内存空间!!   一.内存管理原理:   在java中,有java程序.虚拟机.操作系统三个层次,其中java程序与虚拟机交互,而虚拟机与操作系统间交 ...

  10. Codeforces 768A Oath of the Night's Watch 2017-02-21 22:13 39人阅读 评论(0) 收藏

    A. Oath of the Night's Watch time limit per test 2 seconds memory limit per test 256 megabytes input ...