A:答案一定包含首位或末位。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 300010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,a[N];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
for (int i=1;i<=n;i++) a[i]=read();
if (a[1]!=a[n]) cout<<n-1;
else
{
int ans=0;
for (int i=n;i>=1;i--) if (a[i]!=a[1]) ans=max(ans,i-1);
for (int i=1;i<=n;i++) if (a[i]!=a[n]) ans=max(ans,n-i);
cout<<ans;
}
return 0;
//NOTICE LONG LONG!!!!!
}

  B:二分答案,大的匹配大的即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 1010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,h,a[N],b[N];
bool check(int k)
{
for (int i=1;i<=k;i++) b[i]=a[i];
sort(b+1,b+k+1);
ll s=0;
for (int i=k;i>0;i-=2) s+=b[i];
return s<=h;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),h=read();
for (int i=1;i<=n;i++) a[i]=read();
int l=1,r=n,ans=1;
while (l<=r)
{
int mid=l+r>>1;
if (check(mid)) ans=mid,l=mid+1;
else r=mid-1;
}
cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}

  C:显然将两矩阵xor一下后相当于将矩阵变为全0矩阵,大胆猜想要求每行每列都有偶数个1即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 510
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,a[N][N],b[N][N];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read();
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
a[i][j]=read();
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
a[i][j]^=read();
for (int i=1;i<=n;i++)
{
int s=0;
for (int j=1;j<=m;j++)
s^=a[i][j];
if (s&1) {cout<<"NO";return 0;}
}
for (int i=1;i<=m;i++)
{
int s=0;
for (int j=1;j<=n;j++)
s^=a[j][i];
if (s&1) {cout<<"NO";return 0;}
}
cout<<"YES";
return 0;
//NOTICE LONG LONG!!!!!
}

  D:显然询问的答案只与长度有关,离线按长度从小到大排序,相当于一个不断合并间隙的过程,将间隙长度排序记录已经有多少个被填满即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,q;
ll a[N],ans[N],d[N];
struct data
{
ll k,i;
bool operator <(const data&a) const
{
return k<a.k;
}
}b[N];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
for (int i=1;i<=n;i++) scanf("%I64d",&a[i]);
sort(a+1,a+n+1);
for (int i=2;i<=n;i++) d[i]=a[i]-a[i-1];
sort(d+2,d+n+1);
q=read();
for (int i=1;i<=q;i++)
{
ll l,r;scanf("%I64d%I64d",&l,&r);
b[i].k=r-l+1;b[i].i=i;
}
sort(b+1,b+q+1);
int cnt=n,x=1;
for (int i=1;i<=q;i++)
{
ans[b[i].i]=ans[b[i-1].i];
while (x<n&&d[x+1]<=b[i].k) ans[b[i].i]-=b[i-1].k,x++,cnt--,ans[b[i].i]+=d[x];
ans[b[i].i]+=1ll*cnt*(b[i].k-b[i-1].k);
}
for (int i=1;i<=q;i++) printf("%I64d ",ans[i]);
return 0;
//NOTICE LONG LONG!!!!!
}

  E:显然三角形一定等腰且腰为最长边,瞎贪心,从小到大考虑边长,让其先尽量与之前的短边组成三角形,若有剩余则内部消化,最后留下的边留给更长的边匹配。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 300010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,a[N];
ll ans,x=0;
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
for (int i=1;i<=n;i++) a[i]=read();
for (int i=1;i<=n;i++)
{
if (a[i]>=x*2)
{
ans+=x,a[i]-=x*2,x=0;
ans+=a[i]/3,x=a[i]%3;
}
else
{
ans+=a[i]/2,x-=a[i]/2,x+=a[i]%2;
}
}
cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}

  F:考虑对于单次询问怎么做,显然有dpf[i][0/1]表示在i连向父亲的这条边是否切的情况下,i子树内所有点都满足条件的最小代价,转移将儿子按f[][0]-f[][1]排下序即可。注意到度数>=x的点的个数是O(n/x)的,所以对于所有询问,需要考虑的点的总数只有O(nlogn)个。但同时这些点还会与度数<x的点相连,这些边也可以提供贡献,这一部分可以用平衡树维护,dp时在平衡树上二分决定删除哪些边即可。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 250010
#define inf 10000000000000000ll
#define lson tree[k].ch[0]
#define rson tree[k].ch[1]
mt19937 rnd(20020509);
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int _,n,p[N],degree[N],root[N],id[N],t,cnt;
bool vis[N];
ll f[N][2],S[N],a[N];
struct data{int to,nxt,len;
}edge[N<<1];
struct data2{int ch[2],p,size,x;ll sum;
}tree[N<<1];
void addedge(int x,int y,int z){t++;edge[t].to=y,edge[t].nxt=p[x],edge[t].len=z,p[x]=t;}
bool cmp(const int&a,const int&b)
{
return degree[a]<degree[b];
}
ll query(int k,int x,int s)
{
if (x==0) return 0;
if (k==0) return x>s?inf:S[x];
if (tree[lson].size>=x) return query(lson,x,s);
if (x-tree[lson].size>s) return query(rson,x-tree[lson].size-1,s)+tree[lson].sum+tree[k].x;
ll t=tree[lson].sum+tree[k].x+S[x-tree[lson].size-1];
if (tree[k].x<=a[x-tree[lson].size]) return t=min(t,tree[lson].sum+tree[k].x+query(rson,x-tree[lson].size-1,s));
else return t=min(t,query(lson,x,s));
return t;
}
void up(int k)
{
tree[k].size=tree[lson].size+tree[rson].size+1;
tree[k].sum=tree[lson].sum+tree[rson].sum+tree[k].x;
}
void move(int &k,int p)
{
int t=tree[k].ch[p];
tree[k].ch[p]=tree[t].ch[!p],tree[t].ch[!p]=k,up(k),up(t),k=t;
}
void ins(int &k,int x)
{
if (k==0) {k=++cnt;tree[k].p=rnd(),tree[k].size=1,tree[k].sum=tree[k].x=x;return;}
if (tree[k].x<x) {ins(rson,x);if (tree[rson].p>tree[k].p) move(k,1);}
else {ins(lson,x);if (tree[lson].p>tree[k].p) move(k,0);}
up(k);
}
void dfs(int k,int from)
{
vis[k]=1;int x=0;bool isroot=1;f[k][0]=f[k][1]=0;
int last=0;
for (int i=p[k];i;i=edge[i].nxt)
if (degree[edge[i].to]>_)
{
if (!vis[edge[i].to]) dfs(edge[i].to,k),f[k][0]+=f[edge[i].to][1],f[k][1]+=f[edge[i].to][1];
else f[k][0]+=edge[i].len,isroot=0;
last=i;
}
else if (last) edge[last].nxt=edge[i].nxt;else p[k]=edge[i].nxt;
for (int i=p[k];i;i=edge[i].nxt)
if (degree[edge[i].to]>_&&edge[i].to!=from) a[++x]=f[edge[i].to][0]-f[edge[i].to][1];
sort(a+1,a+x+1);
for (int i=1;i<=x;i++) S[i]=S[i-1]+a[i];
for (int i=x;i>=0;i--)
if (a[i]<=0)
{
if (degree[k]-i<=_) f[k][1]+=S[i];
else f[k][1]+=query(root[k],degree[k]-_,x);
break;
}
if (!isroot)
{
for (int i=x;i>=0;i--)
if (a[i]<=0)
{
if (degree[k]-1-i<=_) f[k][0]+=S[i];
else f[k][0]+=query(root[k],degree[k]-1-_,x);
break;
}
}
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
for (int i=1;i<n;i++)
{
int x=read(),y=read(),z=read();
addedge(x,y,z),addedge(y,x,z);
degree[x]++,degree[y]++;
}
for (int i=1;i<=n;i++) id[i]=i;
sort(id+1,id+n+1,cmp);
int x=1;
for (_=0;_<n;_++)
{
while (x<=n&&degree[id[x]]<=_)
{
for (int j=p[id[x]];j;j=edge[j].nxt)
ins(root[edge[j].to],edge[j].len);
x++;
}
for (int j=x;j<=n;j++) vis[id[j]]=0;
ll ans=0;
for (int j=x;j<=n;j++)
if (!vis[id[j]])
{
dfs(id[j],id[j]);
ans+=f[id[j]][1];
}
//for (int i=1;i<=n;i++) cout<<f[i][0]<<' '<<f[i][1]<<endl;
printf("%I64d ",ans);
}
return 0;
//NOTICE LONG LONG!!!!!
}

  G、H:咕咕咕

  小号打的。这种场真是不管打成什么样都能涨分。result:rank 310 rating +7

Codeforces Global Round 2的更多相关文章

  1. CodeForces Global Round 1

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

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

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

  3. Codeforces Global Round 2 题解

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

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

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

  5. Codeforces Global Round 3

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

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

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

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

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

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

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

  9. 【Codeforces Round 1110】Codeforces Global Round 1

    Codeforces Round 1110 这场比赛只做了\(A\).\(B\).\(C\),排名\(905\),不好. 主要的问题在\(D\)题上,有\(505\)人做出,但我没做出来. 考虑的时候 ...

  10. 树形DP ---- Codeforces Global Round 2 F. Niyaz and Small Degrees引发的一场血案

    Aspirations:没有结果,没有成绩,acm是否有意义?它最大的意义就是让我培养快速理解和应用一个个未知知识点的能力. ————————————————————————————————————— ...

随机推荐

  1. OPC协议解析-关于OPC协议的几个问题

    1    什么是OPC协议? 为了便于自动化行业不同厂家的设备和应用程序能相互交换数据,定义了一个统一的接口函数,就是OPC协议规范.有了OPC就可以使用统一的方式去访问不同设备厂商的产品数据. OP ...

  2. Adapter刷新数据的坑

    adapter刷新数据的时候,要能够刷新成功,要保证每次刷新的时候都是改变数据源. 于是,我这样做了,在适配器的构造方法里面写到: private List<ListBean> listI ...

  3. 转摘app测试方法总结

    app测试方法总结   一.安全测试 1.软件权限 1)扣费风险:包括短信.拨打电话.连接网络等. 2)隐私泄露风险:包括访问手机信息.访问联系人信息等. 3)对App的输入有效性校验.认证.授权.数 ...

  4. Linux内存描述之内存节点node--Linux内存管理(二)

    1 内存节点node 1.1 为什么要用node来描述内存 这点前面是说的很明白了, NUMA结构下, 每个处理器CPU与一个本地内存直接相连, 而不同处理器之前则通过总线进行进一步的连接, 因此相对 ...

  5. c/c++ 多线程 mutex的理解

    多线程 mutex的理解 mutex,我的理解是每个mutex对象都是一个带锁头的门,这个门有两个状态,门开着和门关着,感觉像是废话... 当想查看门的里东西,或者把东西放进门里,或者从门里拿出东西前 ...

  6. C#ComboBox绑定List

    ComboBox绑定List时可能会错, public class Person { public string Name; public int Age; public int Heigth; } ...

  7. ibm z14大型主机介绍

    IBM z14™大型主机 (z14)被设计为数字经济中值得信任的基础架构.它提供  特性和功能以满足对于新服务和更佳客户体验的需求,同时保护日益  增长的数据量,并遵从日益复杂的法规.IBM z14 ...

  8. 如何提高 windows 的使用效率?--巧用运行命令

    windows 操作系统可以使用 win+R 运行一些命令执行任务,好处是:高效.快速.准确. 启动程序 将程序 chrome 写入以下注册表中, SOFTWARE\Microsoft\Windows ...

  9. SQLServer之创建Transact-SQL DDL触发器

    DDL触发器原理 DDL 触发器用于响应各种数据定义语言 (DDL) 事件. 这些事件主要与以关键字 CREATE.ALTER.DROP.GRANT.DENY.REVOKE 或 UPDATE STAT ...

  10. LeetCode算法题-Design LinkedList(Java实现)

    这是悦乐书的第300次更新,第319篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第168题(顺位题号是707).设计链表的实现.您可以选择使用单链表或双链表.单链表中的 ...