A Codehorses T-shirts

相同长度之间互相转化即可

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<map>
  5. #include<algorithm>
  6. using namespace std;
  7. const int N=105;
  8. int n,a[N],b[N],ans;
  9. string s[N],t[N];
  10. map<string,int>mp;
  11. int main()
  12. {
  13. mp["S"]=1,mp["M"]=2,mp["L"]=3;
  14. mp["XS"]=4,mp["XL"]=5;
  15. mp["XXS"]=6,mp["XXL"]=7;
  16. mp["XXXS"]=8,mp["XXXL"]=9;
  17. cin>>n;
  18. for(int i=1;i<=n;i++)
  19. cin>>s[i],a[mp[s[i]]]++;
  20. for(int i=1;i<=n;i++)
  21. cin>>t[i],b[mp[t[i]]]++;
  22. for(int i=1;i<=9;i++)
  23. ans+=abs(a[i]-b[i]);
  24. printf("%d\n",ans/2);
  25. return 0;
  26. }

B Light It Up

把0和m点插进去,处理出s[0/1][i]为i&1为0或1区间长度的后缀和,然后枚举要插入的区间,贪心的把点插在p[i]+1(区间关灯)或p[i+1]-1(区间开灯),然后取后面反的前缀和更新ans即可

  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. const int N=100005;
  5. int n,m,a[N],s[2][N],ans;
  6. int read()
  7. {
  8. int r=0,f=1;
  9. char p=getchar();
  10. while(p>'9'||p<'0')
  11. {
  12. if(p=='-')
  13. f=-1;
  14. p=getchar();
  15. }
  16. while(p>='0'&&p<='9')
  17. {
  18. r=r*10+p-48;
  19. p=getchar();
  20. }
  21. return r*f;
  22. }
  23. int main()
  24. {
  25. n=read()+2,m=read();
  26. for(int i=2;i<n;i++)
  27. a[i]=read();
  28. a[n]=m;
  29. for(int i=n-1;i>=1;i--)
  30. s[i&1][i]=a[i+1]-a[i]+s[i&1][i+1],s[~i&1][i]=s[~i&1][i+1];
  31. // for(int i=1;i<=n;i++)
  32. // cerr<<s[0][i]<<" "<<s[1][i]<<endl;
  33. ans=s[1][1];
  34. for(int i=1;i<n;i++)
  35. if(a[i+1]-a[i]>1)
  36. ans=max(ans,s[1][1]-s[1][i]+s[i&1][i+1]+a[i+1]-a[i]-1);//,cerr<<i<<" "<<s[1][1]-s[1][i]<<" "<<s[i&1][i+1]<<" "<<a[i+1]-a[i]-1<<endl;
  37. printf("%d\n",ans);
  38. return 0;
  39. }

C Covered Points Count

hash一下左右端点,差分前缀和处理出hash后的点(代表这之后的一整段区间)的被覆盖次数,然后把区间长度加进相应的长度ans里即可

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<map>
  5. using namespace std;
  6. const int N=500005;
  7. long long n,tot,has,a[N],l[N],r[N],g[N],rl[N],ans[N];
  8. map<long long,long long>mp;
  9. long long read()
  10. {
  11. long long r=0,f=1;
  12. char p=getchar();
  13. while(p>'9'||p<'0')
  14. {
  15. if(p=='-')
  16. f=-1;
  17. p=getchar();
  18. }
  19. while(p>='0'&&p<='9')
  20. {
  21. r=r*10+p-48;
  22. p=getchar();
  23. }
  24. return r*f;
  25. }
  26. int main()
  27. {
  28. n=read();
  29. for(long long i=1;i<=n;i++)
  30. l[i]=read(),r[i]=read(),g[++tot]=l[i],g[++tot]=r[i]+1;
  31. sort(g+1,g+1+tot);
  32. for(long long i=1;i<=tot;i++)
  33. if(i==1||g[i]!=g[i-1])
  34. mp[g[i]]=++has,rl[has]=g[i];
  35. for(long long i=1;i<=n;i++)
  36. a[mp[l[i]]]++,a[mp[r[i]+1]]--;
  37. for(long long i=2;i<=has;i++)
  38. a[i]+=a[i-1];
  39. // for(long long i=1;i<=has;i++)
  40. // cerr<<i<<" "<<rl[i]<<" "<<a[i]<<endl;
  41. for(long long i=1;i<has;i++)
  42. ans[a[i]]+=rl[i+1]-rl[i];
  43. for(long long i=1;i<=n;i++)
  44. printf("%lld ",ans[i]);
  45. return 0;
  46. }

D Yet Another Problem On a Subsequence

考的时候没做出来

设f[i]为选i为一个a1的方案数,转移是\( f[i]=\sum_{j=i+a[i]+1}{n+1}C_{i-j-1}{a[i]}*f[j] \) 最后的答案是\( ans=\sum_{i=1}^{n}f[i] \)

  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. const int N=1005,mod=998244353;
  5. int n,a[N],f[N],ans,c[N][N];
  6. void jia(int &x,int y)
  7. {
  8. x+=y;
  9. if(x>=mod)
  10. x-=mod;
  11. }
  12. int main()
  13. {
  14. scanf("%d",&n);
  15. for(int i=1;i<=n;i++)
  16. scanf("%d",&a[i]);
  17. c[0][0]=1;
  18. for(int i=1;i<=n;i++)
  19. {
  20. c[i][0]=1;
  21. for(int j=1;j<=i;j++)
  22. c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
  23. }
  24. f[n+1]=1;
  25. for(int i=n;i>=1;i--)
  26. if(a[i]>0)
  27. {
  28. for(int j=i+a[i]+1;j<=n+1;j++)
  29. jia(f[i],1ll*c[j-i-1][a[i]]*f[j]%mod);
  30. jia(ans,f[i]);
  31. }
  32. printf("%d\n",ans);
  33. return 0;
  34. }

E We Need More Bosses

比较裸,先缩了边双然后求树的直径即可

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. using namespace std;
  5. const int N=300005;
  6. int n,m,h[N],cnt,dfn[N],low[N],tot,s[N],top,bl[N],col,con,st,mx;
  7. bool v[N];
  8. pair<int,int>b[N<<1];
  9. struct qwe
  10. {
  11. int ne,no,to;
  12. }e[N<<1];
  13. int read()
  14. {
  15. int r=0,f=1;
  16. char p=getchar();
  17. while(p>'9'||p<'0')
  18. {
  19. if(p=='-')
  20. f=-1;
  21. p=getchar();
  22. }
  23. while(p>='0'&&p<='9')
  24. {
  25. r=r*10+p-48;
  26. p=getchar();
  27. }
  28. return r*f;
  29. }
  30. void add(int u,int v)
  31. {
  32. cnt++;
  33. e[cnt].ne=h[u];
  34. e[cnt].no=u;
  35. e[cnt].to=v;
  36. h[u]=cnt;
  37. }
  38. void tarjan(int u,int fa)
  39. {
  40. dfn[u]=low[u]=++tot;
  41. s[++top]=u;
  42. for(int i=h[u];i;i=e[i].ne)
  43. if(e[i].to!=fa)
  44. {
  45. if(!dfn[e[i].to])
  46. {
  47. tarjan(e[i].to,u);
  48. low[u]=min(low[u],low[e[i].to]);
  49. }
  50. else
  51. low[u]=min(low[u],dfn[e[i].to]);
  52. }
  53. if(low[u]==dfn[u])
  54. {
  55. col++;
  56. while(s[top]!=u)
  57. bl[s[top--]]=col;
  58. bl[s[top--]]=col;
  59. }
  60. }
  61. void dfs(int u,int fa,int len)
  62. {
  63. if(len>mx)
  64. st=u,mx=len;
  65. for(int i=h[u];i;i=e[i].ne)
  66. if(e[i].to!=fa)
  67. dfs(e[i].to,u,len+1);
  68. }
  69. int main()
  70. {
  71. n=read(),m=read();
  72. for(int i=1;i<=m;i++)
  73. {
  74. int x=read(),y=read();
  75. add(x,y),add(y,x);
  76. }
  77. tarjan(1,0);
  78. for(int i=1;i<=cnt;i++)
  79. if(bl[e[i].no]!=bl[e[i].to])
  80. b[++con]=make_pair(bl[e[i].no],bl[e[i].to]);
  81. memset(h,0,sizeof(h));
  82. cnt=0;
  83. for(int i=1;i<=con;i++)
  84. add(b[i].first,b[i].second);
  85. dfs(1,0,0);
  86. mx=0;
  87. dfs(st,0,0);
  88. printf("%d\n",mx);
  89. return 0;
  90. }

Codeforces 1000 (A~E)的更多相关文章

  1. Codeforces 1000 组合数可行线段倒dp 边双联通缩点求树直径

    A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace std ...

  2. Educational Codeforces Round 46 (Div 2) (A~G)

    目录 Codeforces 1000 A.Codehorses T-shirts B.Light It Up C.Covered Points Count(差分) D.Yet Another Prob ...

  3. TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E

    传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...

  4. 【Codeforces】Educational Codeforces Round 46(Contest 1000)

    题目 传送门:QWQ A:Codehorses T-shirts 题意: 给定一些字符串表示去年和今年的衣服型号大小( XL XXL M...... ),要求用最少的次数把去年的衣服大小改成今年需要的 ...

  5. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

  6. Codeforces Round #344 (Div. 2) A. Interview

    //http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. Codeforces Training S03E01泛做

    http://codeforces.com/gym/101078 和ysy.方老师一起打的virtual 打的不是很好...下面按过题顺序放一下过的题的题(dai)解(ma). A 给两个1~n的排列 ...

  9. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)

    A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...

随机推荐

  1. 自动检查出修改的代码 shell 做升级包 供观摩

    #!/bin/bash # 检测出 appsReleass 项目代码更新 # oath 冉幕飞 #验证 基础参数 $1 day=$1 #多少天内 zipfile=$2 #包名称 if [ " ...

  2. github 新建远程仓库 及 删除远程仓库

    一.新建远程仓库 1.点击 ' + ' 号 2.选择 ' new repository ' 3.填写信息  创建仓库 二.删除远程仓库 1.点击 ' Settings ' 按钮 2.滑动到最底部,点击 ...

  3. MongoDB---出现no write has been done on this connection解决方式

    no write has been done on this connection 这个问题出现了好几天.日志里面一天出现几十次no write has been done on this conne ...

  4. GCD编程(封装GCD)

    //GCDGroup 类 @interface GCDGroup : NSObject @property (strong, nonatomic, readonly) dispatch_group_t ...

  5. requirejs中的define

    关于requirejs中的define的原理理解   我们已经了解到模块模式是为单例创建私有变量和特权方法的.一个最基本的例子: var foo=(function(){ var something= ...

  6. 未来 5 年八大热门 IT 职业

    近日.外媒梳理了未来5年内.也是就是2020年仍将受到热捧的八大科技领域,为IT从业者怎样做好长远规划.有针对性地培养自身技能.又不偏离热门岗位提供了參考. (图片来自网易) 2020年将热门的8大I ...

  7. java的多态以及重载,重写,前期绑定,后期绑定

    多态的定义: 一个类实例的相同方法在不同情形有不同表现形式.多态机制使具有不同内部结构的对象可以共享相同的外部接口.这意味着,虽然针对不同对象的具体操作不同,但通过一个公共的类,它们(那些操作)可以通 ...

  8. 用python编写的简易端口扫描器

    #coding = utf-8 ''' python 3.4 通过简单的TCP端口连接来判断指定IP是否开放了指定端口. ''' import socket import optparse impor ...

  9. linux下提示command not found

    首先就要考虑root 的$PATH里是否已经包含了这些环境变量. 主要是这四个:/bin ,/usr/bin,/sbin,/usr/sbin. 四个主要存放的东东: ./bin: bin为binary ...

  10. HDU 6073 Matching In Multiplication dfs遍历环 + 拓扑

    Matching In Multiplication Problem DescriptionIn the mathematical discipline of graph theory, a bipa ...