不想欠题了..... 多打打CF才知道自己智商不足啊...

A. Vladik and flights

给你一个01串  相同之间随便飞 没有费用 不同的飞需要费用为  abs i-j

真是题意杀啊,,,实际上我们只考虑01转换的代价一定为1如果目的地和起点相同  费用为0

不相同  肯定为1  因为0旁边必然有1

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <set>
  6. #include <string.h>
  7. #include <cctype>
  8. #include <climits>
  9. using namespace std;
  10. typedef long long ll;
  11. template <class T>
  12. inline bool r(T &ret)
  13. {
  14. char c;
  15. int sgn;
  16. if (c = getchar(), c == EOF)
  17. {
  18. return ; //EOF
  19. }
  20. while (c != '-' && (c < '' || c > ''))
  21. {
  22. c = getchar();
  23. }
  24. sgn = (c == '-') ? - : ;
  25. ret = (c == '-') ? : (c - '');
  26. while (c = getchar(), c >= '' && c <= '')
  27. {
  28. ret = ret * + (c - '');
  29. }
  30. ret *= sgn;
  31. return ;
  32. }
  33. const int N = 1e5+;
  34. char ch[N];
  35. int main()
  36. {
  37. int n;
  38. r(n);
  39. int x,y;
  40. r(x),r(y);
  41. scanf("%s",ch+);
  42. if(ch[x]==ch[y])
  43. {
  44. printf("0\n");
  45. }
  46. else{
  47. printf("1\n");
  48. }
  49. return ;
  50. }

zz

B. Chloe and the sequence

给一个n,然后按照 1  121 1213121 的第n个串

那么肯定是二分n次必得....  赛场拿python写的   (L+R)没加括号T1

  1. n,k = map(int, input().split())
  2. def calc(k):
  3. L =
  4. R = **n
  5. M = L+R//
  6. ans =
  7. while(k!=M):
  8. if(k>M):
  9. L = M
  10. else:
  11. R = M
  12. M = (L+R)//
  13. ans+=
  14. print(n-ans)
  15. calc(k)

Py

C. Vladik and fractions

问2/n能不能由1/a+1/b+1/c(a,b,c互不相同) 太粗心,没看到互不相同 wa1 没特判1 被hack 1

手推 a = n b = n+1 c = n*(n+1)

n=1分不出的

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <set>
  6. #include <string.h>
  7. #include <cctype>
  8. #include <climits>
  9. using namespace std;
  10. typedef long long ll;
  11. template <class T>
  12. inline bool r(T &ret)
  13. {
  14. char c;
  15. int sgn;
  16. if (c = getchar(), c == EOF)
  17. {
  18. return ; //EOF
  19. }
  20. while (c != '-' && (c < '' || c > ''))
  21. {
  22. c = getchar();
  23. }
  24. sgn = (c == '-') ? - : ;
  25. ret = (c == '-') ? : (c - '');
  26. while (c = getchar(), c >= '' && c <= '')
  27. {
  28. ret = ret * + (c - '');
  29. }
  30. ret *= sgn;
  31. return ;
  32. }
  33.  
  34. int main()
  35. {
  36. int n;
  37. r(n);
  38. if(n==) printf("-1");
  39. else printf("%d %d %d\n",n,n+,n*(n+));
  40. return ;
  41. }

AC

D.Chloe and pleasant prizes

带权有根树  选两个不相交子树的之和最大,裸DFS。

吐槽一下自己奇差无比的代码。。。两个dfs才完成任务...

还因为各种写搓  wa了3次

  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <limits.h>
  5. #include <vector>
  6. using namespace std;
  7. typedef long long ll;
  8. const int N = 2e5+;
  9. vector<int>g[N];
  10. ll sum[N];
  11. ll son[N];
  12. int a[N];
  13. void push(int x,int y){g[x].push_back(y);g[y].push_back(x);}
  14. bool flag = true;
  15. void UMAX(ll& a,ll& b,ll c){
  16. if(c>a)
  17. {
  18. b = a;
  19. a = c;
  20. }
  21. else{
  22. if(c>=b)
  23. {
  24. b = c;
  25. }
  26. }
  27. }
  28. ll dfs(int now,int pre)
  29. {
  30. sum[now] += a[now];
  31.  
  32. bool mk = true;
  33. for(int i=;i<g[now].size();i++)
  34. {
  35. if(g[now][i]==pre) continue;
  36. ll val = dfs(g[now][i],now);
  37. sum[now] += val;
  38. if(!mk)son[now] = max(son[now],son[g[now][i]]);
  39. else{
  40. mk = false;
  41. son[now] = son[g[now][i]];
  42. }
  43. }
  44. if(mk)son[now] = a[now];
  45. son[now] = max(son[now],sum[now]);
  46. return sum[now];
  47. }
  48. ll ans = LONG_LONG_MIN;
  49. void F(int now,int pre)
  50. {
  51. //cout<<now<<endl;
  52. ll a = LONG_LONG_MIN;
  53. ll b = LONG_LONG_MIN;
  54. for(int i=;i<g[now].size();i++)
  55. {
  56. if(pre==g[now][i]) continue;
  57. UMAX(a,b,son[g[now][i]]);
  58. F(g[now][i],now);
  59. }
  60. //if(now==4) cout<<a<<" "<<b<<endl;
  61. if(b!=LONG_LONG_MIN)ans = max(ans,a+b);
  62. }
  63. int main()
  64. {
  65. int n;
  66. scanf("%d",&n);
  67. for(int i=;i<=n;i++)
  68. {
  69. scanf("%d",&a[i]);
  70. }
  71. int x,y;
  72. for(int i=;i<n;i++)
  73. {
  74. scanf("%d%d",&x,&y);
  75. push(x,y);
  76. }
  77. dfs(,-);
  78. /*
  79. for(int i=1;i<=n;i++)
  80. printf("%d\t",i);
  81. printf("\n");
  82. for(int i=1;i<=n;i++)
  83. printf("%I64d\t",sum[i]);
  84. printf("\n");
  85. for(int i=1;i<=n;i++)
  86. printf("%I64d\t",son[i]);
  87. printf("\n");
  88. //*/
  89. F(,-);
  90. if(ans==LONG_LONG_MIN)
  91. printf("Impossible\n");
  92. else{
  93. printf("%I64d\n",ans);
  94. }
  95. return ;
  96. }

AC代码

贴一下陈老师的代码....

  1. #include<cstdio>
  2. #include<algorithm>
  3. typedef long long ll;
  4. const int N=;
  5. const ll inf=1LL<<;
  6. int n,i,x,y,a[N],g[N],v[N<<],nxt[N<<],ed;ll f[N],dp[N],ans=-inf;
  7. inline void add(int x,int y){v[++ed]=y;nxt[ed]=g[x];g[x]=ed;}
  8. void dfs(int x,int y){
  9. f[x]=a[x];
  10. dp[x]=-inf;
  11. for(int i=g[x];i;i=nxt[i]){
  12. int u=v[i];
  13. if(u==y)continue;
  14. dfs(u,x);
  15. f[x]+=f[u];
  16. if(dp[x]>-inf)ans=std::max(ans,dp[x]+dp[u]);
  17. dp[x]=std::max(dp[x],dp[u]);
  18. }
  19. dp[x]=std::max(dp[x],f[x]);
  20. }
  21. int main(){
  22. scanf("%d",&n);
  23. for(i=;i<=n;i++)scanf("%d",&a[i]);
  24. for(i=;i<n;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
  25. dfs(,);
  26. if(ans>-inf)printf("%I64d",ans);else puts("Impossible");
  27. }

claris

 
 

E. Vladik and cards

题意给以一个1-8组成的串  选出一个子串(在原串中可以不连续)  选出来的串 每个数相同的一定相邻  而且 每种数的个数相差不超过1

比赛时只想到DFS的解,后来证实是错的

后来看别人的代码一脸蒙=。=... 后来一神说了两个数组的作用才明白...就这样   参考claris的写法

而且....

这样也写了好久  而且还少更新状态   长度可以为0......

  1. #include<cstdio>
  2. #include<cstring>
  3. void Min(int &a,int b) {if(a>b) a=b;}
  4. void Max(int &a,int b) {if(a<b) a=b;}
  5. const int maxn = ;
  6. int cnt[];
  7. int g[maxn][maxn][];//i j k
  8. int dp[][];//i 选择方案 j 代表 长度的集合个数 长度最多n/8+1
  9. int val[maxn];
  10. int n;
  11. int main()
  12. {
  13. scanf("%d",&n);
  14. for(int i=;i<=n;i++) scanf("%d",&val[i]),val[i]--;
  15. for(int i=;i<=n;i++)
  16. {
  17. for(int j=;j<=n+;j++)
  18. for(int k=;k<=;k++) g[i][j][k] = maxn;
  19. memset(cnt,,sizeof(cnt));
  20. for(int j=i;j<=n;j++)
  21. g[i][++cnt[val[j]]][val[j]] = j;
  22. }
  23. int ans = ;
  24. for(int i=;i*<=n;i++)//长度
  25. {
  26. for(int j=;j<;j++)
  27. for(int k=;k<=;k++)
  28. dp[j][k] = maxn;
  29. dp[][] = ; //从1开始
  30. for(int j=;j<;j++)//选择方案
  31. {
  32. for(int k=;k<=;k++)//
  33. {
  34. if(dp[j][k]>n)continue;
  35. for(int l=;l<;l++)
  36. {
  37. if((<<l)&j) continue;
  38. Min(dp[j|(<<l)][k],g[dp[j][k]][i][l]+);
  39. Min(dp[j|(<<l)][k+],g[dp[j][k]][i+][l]+);
  40. }
  41. }
  42. }
  43. for(int j=;j<=;j++) if(dp[][j]<n+){
  44. Max(ans,j+*i);
  45. }
  46. }
  47. printf("%d\n",ans);
  48. return ;
  49. }

状压DP

Codeforces Round #384 (Div. 2) //复习状压... 罚时爆炸 BOOM _DONE的更多相关文章

  1. Codeforces Round #384(div 2)

    A 题意:有n个机场处于一直线上,可两两到达,每个机场只可能属于两家公司中的一家(用0,1表示),现在要从a机场到b机场,可任意次转机.若机场i与机场j从属同一公司,则费用为0,否则费用为1.问最小费 ...

  2. Codeforces Round #384 (Div. 2) E

    给出n个数字 1-8之间 要求选出来一个子序列 使里面1-8的数字个数 极差<=1 并且相同数字必须相邻(112 可以但是121不行)求这个子序列的最长长度 一道状压dp 看不懂别人的dp思想. ...

  3. Codeforces Round #384 (Div. 2) E. Vladik and cards 状压dp

    E. Vladik and cards 题目链接 http://codeforces.com/contest/743/problem/E 题面 Vladik was bored on his way ...

  4. Codeforces Round #384 (Div. 2)D - Chloe and pleasant prizes 树形dp

    D - Chloe and pleasant prizes 链接 http://codeforces.com/contest/743/problem/D 题面 Generous sponsors of ...

  5. Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题

    C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...

  6. Codeforces Round #384 (Div. 2)B. Chloe and the sequence 数学

    B. Chloe and the sequence 题目链接 http://codeforces.com/contest/743/problem/B 题面 Chloe, the same as Vla ...

  7. Codeforces Round #384 (Div. 2) A. Vladik and flights 水题

    A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...

  8. Codeforces Round #384 (Div. 2) C. Vladik and fractions(构造题)

    传送门 Description Vladik and Chloe decided to determine who of them is better at math. Vladik claimed ...

  9. Codeforces Round #384 (Div. 2) B. Chloe and the sequence(规律题)

    传送门 Description Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems ...

随机推荐

  1. Webpack 入门指南 - 2.模块

    这一次我们谈谈模块问题. 通常我们希望这个项目可以分为多个独立的模块,比如,上一次提高的 hello 函数,如果我们定义为一个模块,其它模块引用之后,直接调用就好了.在前端怎么使用模块呢?这可说来话长 ...

  2. window.frame

    定义和用法 frames 属性返回窗口中所有命名的框架. 该集合是 Window 对象的数组,每个 Window 对象在窗口中含有一个框架或 <iframe>.属性 frames.leng ...

  3. 自己用c语言实现字符串处理库函数以及扩展

    1.实现基本的c语言库函数: int myStrlen( const char* str);//根据传入的字符串首地址获取字符串长度:返回值为长度 int myStrlen(const char* s ...

  4. php 正则表达式 将形如 "天," ,"安", "门" 转化为"天、安、门", (仅匹配汉字)

    #!/usr/bin/php<? $rows = file("illwods_deal1.txt"); $goalfile = fopen("illwods_res ...

  5. form中的GET与POST

     form标签是强大的:如果没有form标签,Internet将变成一个枯燥文档的只读存储库.Web Forms没有完全利用form标签的强大功能(也可以说是Web Forms为实现自己的目标才管理和 ...

  6. Mysql常见四种索引的使用

    提到MySQL优化,索引优化是必不可少的.其中一种优化方式 --索引优化,添加合适的索引能够让项目的并发能力和抗压能力得到明显的提升. 我们知道项目性能的瓶颈主要是在"查(select)&q ...

  7. 逻辑运算符&&和&的区别 ||和|的区别

    A:最终结果一样. B:&& 和 || 有短路作用,左边是false ,右边不执行.

  8. ARCGIS如何进行可视域分析

    可视域分析在不同的领域有着广泛的应用,如火灾监控点的设定,观察哨所的设定等等.军事领域是可视域分析技术应用最广的领域.例如为了设计巡航导弹的航线,就必须对发射点到目标的地形进行分析,包括地形特征优劣分 ...

  9. SequoiaDB 笔记

    SequoiaDB 笔记 这几天翻了翻SequoiaDB的代码,记了点笔记.不保证下面内容的正确性(肯定有错的地方) 个人观感 优点 代码还不错,设计也算简洁. EDU和CB的使用让整个系统变得简单很 ...

  10. QNDataSet打印预览自动关闭问题

    问题:打印预览后,数据集自动关闭 解决: TQNDataSet = class(TFDMemTable) private protected procedure PSReset; override; ...