zoukankan      html  css  js  c++  java
  • BZOJ 刷题记录 PART 6

    【BZOJ2709】水的二分加验证。可是好像被读入萎到了。。。

    【BZOJ3229】强大的算法见此。被机房的一堆大神“推荐”。于是被坑了。。。写了一个下午。。。

    【BZOJ3631】这道题给我的启发是:要多想想算法。

    開始一直在打树链剖分,打到一半忽然在众神犇的提(bi)示(shi)下。发现有O(N)的方法。试想:假设要支持区间改动(加减),最后再查询,能够用什么方法?固然,线段树和树状数组等等都能够,可是最好的显然是类似于前缀和的思想。比方在L~R加上一个数,能够再L处+K。在R+1处-K。

    然后最后的时候从头到尾扫过去、累加就可以。      

    那么这道题实际上是在树上做这个类似的操作。当然,求LCA的时候要用tarjan,否则效率又变回去了。

    下面是代码。wri是为了调整,最后输出的是wri和sum的和。

    void bfs(int k)
    {
      for (int i=1;i<n;i++)
      {
        int x=opt[i],y=opt[i+1];
        sum[ans[i]]-=2;
        sum[x]++;sum[y]++;
        wri[y]--;wri[ans[i]]++;
      }
      int h=0,t=1;q[1]=1;
      while (h<t) 
      {
        int now=q[++h];
        for (int i=end[now];i;i=a[i].next)
        {
          int go=a[i].go;if (go==fa[now]) continue;
          q[++t]=go;
        }
      }
      for (int j=t;j;j--) 
      {
        int k=q[j];
        sum[fa[k]]+=sum[k];
      }
    }

    【BZOJ3609】打表找规律。据说是版权问题?就不说了。

    【BZOJ1212】啊哈哈哈。又被我DP使过去啦!

    【BZOJ2823&1666&1667】曾经查来的题解。。。

    好像是谁的论文来着。

    初始圆为1,2作为直径的圆。
    For i=2 to n
    If i不在当前圆内 then
       把当前圆设为以1,i为直径的圆
        For j=2 to i-2
        If j不在当前圆内 then
        把当前圆设为以j,i为直径的圆{确定初始圆}
            For k=1 to j-1
            If k不在当前圆内 then
               把当前圆设为I,j,k三点确定的圆。{确定三点确定的圆}
    输出当前圆

    【BZOJ1802】真的是好题。我们先来考虑在开头的时候放的尽量的少。

    ①假设有两个相邻的红格。那么我能够在放好后之后到达不论什么一个点!于是第一问就是0。至于第二问。找出全部相邻的红格,直接用DP往左右扫。

     for (int i=k-1;i;i--)
        f[i]=min(f[i],f[i+1]+f[i+2]);

    ②否则必须在偶数格放棋子。扫一遍就可以。

    for (i=2;i<n;i++)
        if (a[i]&a[i+1]) {flag=1;break;}
      if (!flag) 
      {
        for (i=2;i<n;i++)
          if (!(i&1)) a[i]?ans2++:ans1++;
        printf("%lld
    %lld",ans1,ans2);
        return 0;
      }
      memset(f,60,sizeof(f));
      for (i=1;i<=n;i++) if (a[i]) f[i]=1;
      for (i=2;i<n;i++) 
        if (a[i]&a[i+1]) bfs_left(i),bfs_right(i+1);
      for (i=2;i<n;i++) 
        if (!(i&1)) ans2+=f[i];

    【BZOJ3574】题解传送门(跪SYC大爷!)

    【BZOJ1873】写的天昏地暗!

    我认为有必要贴一下代码。

    #include<cstdio>
    #include<cstring>
    #include<map>
    #include<string>
    #define N 20005
    #define P 41
    using namespace std;
    map<string,int>pre;
    const char Num[11][P]={"","","","killing spree","dominating","mega kill",
    "unstoppable","wicked sick","monster kill","godlike","beyond godlike"};
    const char Wri[11][P]={"","","","is on a killing spree!","is dominating!",
    "has a mega kill!","is unstoppable!","is wicked sick!","has a monster kill!",
    "is godlike!","is beyond godlike. someone kill him!"};
    char a[P],b[P],Time[P],ch[P];
    int belong[N],num[N],kill[N],last[N],death[2];
    int A,B,now_Time,ok_kill,ALL,n,i,Q;
    bool check()
    {
      A=pre[a];B=pre[b];
      return A&&B&&A!=B;
    }
    void get_Time(){now_Time=(Time[0]*10+Time[1])*60+Time[3]*10+Time[4];}
    void First()
    {
      if (A==B) {printf("%s has killed himself.
    ",a);return;}
      if (!ok_kill) {printf("%s has been killed by %s.
    ",b,a);return;}
      if (num[B]>=3) {printf("%s has just ended %s's %s.
    ",a,b,Num[num[B]<=10?

    num[B]:10]);num[B]=0;return;} printf("%s pawned %s's head. ",a,b);num[B]=0; if (ok_kill&&!ALL) ALL=1,printf("%s just drew first blood. ",a); } void Second() { if (!ok_kill) return; num[A]++; if (num[A]>=3) { if (num[A]<=10) printf("%s %s ",a,Wri[num[A]]); else printf("%s %s ",a,Wri[10]); } } void Third() { if (!ok_kill) return; if (kill[A]&&now_Time<=last[A]+10) { if (kill[A]==1) printf("%s just got a Double Kill! ",a); else printf("%s just got a Triple Kill! ",a); } else kill[A]=0; kill[A]++;last[A]=now_Time; } void Fourth() { if (!ok_kill) return; int now=belong[B];death[now]++;death[now^1]=0; if (death[now]>=5) printf("The %s is OWNING! ",!now?"Scourge":"Sentinel"); } int main() { freopen("1873.out","w",stdout); scanf("%d",&n); for (i=1;i<=n;i++) scanf("%s%d",a,&belong[i]),pre[a]=i; scanf("%d",&Q);ALL=0; while (Q--) { scanf("%s%s%s%s%s%s",Time,b,ch,ch,ch,a); ok_kill=check();get_Time(); First();Second();Third();Fourth(); } return 0; }

    【BZOJ1925*】至今还认为奇怪的DP(递推、组合数)。有空去看看。

    【BZOJ1819】好题目!

    用dfs序的性质。树状数组维护,还要求LCA。開始忘了怎么在dfs序的树状数组中维护某个点的子树的信息,去问了RZZ,后来发现根本就是傻X问题啊。

  • 相关阅读:
    python之----------字符编码具体原理
    css部分复习整理
    秘钥登录服务器执行shell脚本
    idea配置github
    InteliJ IDEA 简单使用:配置项目所需jdk
    IntelliJ IDEA 中安装junit插件
    IDEA 运行maven命令时报错: -Dmaven.multiModuleProjectDirectory system propery is not set
    idea如何编译maven项目
    idea项目左边栏只能看到文件看不到项目结构
    idea如何导入一个maven项目
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5097216.html
Copyright © 2011-2022 走看看