Educational Codeforces Round 10

652A - Gabriel and Caterpillar    20171128

按题意模拟即可

#include
#include
#include
#include
#include
#include
using namespace std;
int h1,h2,a,b,ans=1;
int main()
{
    scanf("%d%d%d%d",&h1,&h2,&a,&b);
    if(h1+8*a>=h2)return printf("0\n"),0;
    if(a<=b)return printf("-1\n"),0;
    h1+=8*a-12*b;
    while(true)
      {
      if(h1+12*a>=h2)return printf("%d\n",ans),0;
      h1+=12*(a-b),ans++;
      }
}
View Code

 

652B - z-sort    20171128

排序之后把大的数字放偶数位即可

#include
#include
#include
#include
#include
#include
using namespace std;
int n,a[1001],ans[1001];
int main()
{
    scanf("%d",&n);int N=n;
    for(int i=1;i<=n;i++)
      scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i+=2)ans[i]=a[i+1>>1];
    for(int i=N-(N&1);i>=2;i-=2)ans[i]=a[n--];
    for(int i=1;i<=N;i++)
      printf("%d%c",ans[i],i==N?'\n':' ');
    return 0;
}
View Code

 

652C - Foe Pairs    20171128

对每个数记录所有和他组成Foe Pair的数字位置即可

#include
#include
#include
#define N 300001
#include 
#include
#include
#include
using namespace std;
#define LL long long
#define MOD 1000000007
LL n,m,a,b,ans,p[N],pos[N];
vectorf[N];
int main()
{
    scanf("%I64d%I64d",&n,&m);
    for(LL i=1;i<=n;i++)
      scanf("%I64d",&p[i]),pos[p[i]]=i;
    for(LL i=1;i<=m;i++)
      {
      scanf("%I64d%I64d",&a,&b);
      if(pos[a]>pos[b])
        swap(a,b);
      f[pos[a]].push_back(pos[b]-1);
      }
    LL _=n;
    for(LL i=n;i>=1;i--)
      {
      for(LL j=0;j)
        _=min(_,f[i][j]);
      ans+=_-i+1;
      }
    printf("%I64d\n",ans);
    return 0;
}
View Code

 

652D - Nested Segments    20190312

离散化后用树状数组处理即可

#include
using namespace std;
#define N 200001
int n,l[N],r[N],a[N],f[N],t[N];
map<int,int>mp;
int lowbit(int x){return x&(-x);}
bool cmpl(int x,int y){return l[x]<l[y];}
bool cmpr(int x,int y){return r[x]<r[y];}
void change(int x,int c){while(xlowbit(x);}
int ask(int x){int res=0;while(x)res+=t[x],x-=lowbit(x);return res;}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
      scanf("%d%d",&l[i],&r[i]),a[i]=i;
    sort(a+1,a+n+1,cmpr);
    for(int i=1;i<=n;i++)
      mp[r[a[i]]]=i;
    sort(a+1,a+n+1,cmpl);
    for(int i=1;i<=n;i++)
      change(i,1);
    for(int i=1;i<=n;i++)
      change(mp[r[a[i]]],-1),f[a[i]]=ask(mp[r[a[i]]]);
    for(int i=1;i<=n;i++)printf("%d\n",f[i]);
}
View Code

 

652E - Pursuit For Artifacts    20190402

缩点后深搜一次即可,注意细节处理

#include
using namespace std;
#define N 300001
#define mp make_pair
stack<int>s,t;
vectorint,int> >d[N],d2[N];
int n,m,u,v,z,cnt,dcnt,f[N],dfn[N],low[N],flg[N];
void dfs(int cur,int pre)
{
    s.push(cur);
    low[cur]=dfn[cur]=++dcnt;
    for(auto nxt:d[cur])if(nxt.first!=pre)
      {
      if(!dfn[nxt.first])dfs(nxt.first,cur);
      low[cur]=min(low[cur],low[nxt.first]);
      }
    if(dfn[cur]==low[cur])
      {
      cnt++;
      while(s.top()!=cur)
        f[s.top()]=cnt,t.push(s.top()),s.pop();
      f[s.top()]=cnt,t.push(s.top()),s.pop();
      while(!t.empty())
        {
        int x=t.top();t.pop();
        for(auto y:d[x])
          if(f[x]==f[y.first])
            flg[cnt]|=y.second;
        }
      }
}
void dfs2(int cur,int pre)
{
    flg[cur]|=flg[pre];
    for(auto nxt:d2[cur])
      if(nxt.first!=pre)
        flg[nxt.first]|=nxt.second,
        dfs2(nxt.first,cur);
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
      {
      scanf("%d%d%d",&u,&v,&z);
      d[u].push_back(mp(v,z));
      d[v].push_back(mp(u,z));
      }
    for(int i=1;i<=n;i++)
      sort(d[i].begin(),d[i].end());
    for(int i=1;i<=n;i++)
      if(!dfn[i])dfs(i,0);
    for(int i=1;i<=n;i++)
      for(auto j:d[i])if(f[i]!=f[j.first])
        d2[f[i]].push_back(mp(f[j.first],j.second));
    scanf("%d%d",&u,&v);
    dfs2(f[u],0);
    printf("%s\n",flg[f[v]]?"YES":"NO");
    return 0;
}
View Code

 

652F - Ants on a Circle    20190403

[Educational Round 10][Codeforces 652F. Ants on a Circle]

转载于:https://www.cnblogs.com/DeaphetS/p/10648254.html

你可能感兴趣的:(Educational Codeforces Round 10)