翻车!翻车!

codeforces782A

A题:

水。

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. int num[100010];
  5. int main()
  6. {
  7. int n,x;
  8. memset(num,0,sizeof(num));
  9. scanf("%d",&n);
  10. int sum=0,ans=0;
  11. for(int i=1;i<=2*n;i++)
  12. {
  13. scanf("%d",&x);
  14. if(!num[x])
  15. {
  16. num[x]++;
  17. sum++;
  18. }
  19. else
  20. {
  21. sum--;
  22. num[x]--;
  23. }
  24. ans=max(ans,sum);
  25. }
  26. printf("%d\n",ans);
  27. return 0;
  28. }

codeforces782B

B题:

三分,最短时间的位置位于最大位置和最小位置区间内,而时间是咋算的?所有点到位置的max,so两边扩散,肯定是越来越大,凹形曲线,三分求极值。

PS:注意精度1e-6.

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const double eps=1e-6;
  5. const int N=6e4+10;
  6. struct asd{
  7. double x,v;
  8. }e[N];
  9. int n;
  10. bool cmp(asd a,asd b)
  11. {
  12. if(a.x<b.x) return true;
  13. return false;
  14. }
  15.  
  16. double fun(double x)
  17. {
  18. double ans=0.0;
  19. for(int i=1;i<=n;i++)
  20. if(ans<(fabs(e[i].x-x)/e[i].v))
  21. ans=(fabs(e[i].x-x)/e[i].v);
  22. return ans;
  23. }
  24.  
  25. int main()
  26. {
  27. scanf("%d",&n);
  28. for(int i=1;i<=n;i++)
  29. scanf("%lf",&e[i].x);
  30. for(int i=1;i<=n;i++)
  31. scanf("%lf",&e[i].v);
  32. sort(e+1,e+n+1,cmp);
  33. double Left=e[1].x,Right=e[n].x;
  34. double mid, midmid;
  35. double mid_value, midmid_value;
  36. while (Left +eps < Right)
  37. {
  38. mid = (Left + Right) / 2;
  39. midmid = (mid + Right) / 2;
  40. mid_value = fun(mid);
  41. midmid_value = fun(midmid);
  42. ///求最大值改成>= 最小值改成<=
  43. if (mid_value <= midmid_value) Right = midmid;
  44. else Left = mid;
  45. }
  46. double ans=fun(Left);
  47. printf("%.9lf\n",ans);
  48. return 0;
  49. }

codeforces782C

C题:

利用BFS可以轻松处理。

BFS是一层一层的,对于每个结点的儿子结点,都会有一些可以使用的颜色,except(他父亲的颜色,他父亲的父亲的颜色)。

外送两个案例:

  1. 7
  2. 1 2
  3. 3 2
  4. 2 4
  5. 4 5
  6. 5 6
  7. 5 7
  8.  
  9. 7
  10. 1 2
  11. 2 3
  12. 2 4
  13. 2 5
  14. 5 6
  15. 5 7

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4.  
  5. const int N=4e5+10;
  6.  
  7. struct asd{
  8. int to;
  9. int next;
  10. }e[N];
  11. int head[N],tol;
  12. bool vis[N];
  13. int col[N],pre[N],in[N],t;
  14.  
  15. void BFS(int pos)
  16. {
  17. queue<int>q;
  18. memset(vis,0,sizeof(vis));
  19. pre[0]=pre[pos]=0;
  20. vis[pos]=true;
  21. col[pos]=1;
  22. t=1;
  23. q.push(pos);
  24. while(!q.empty())
  25. {
  26. int u=q.front();q.pop();
  27. int tmp=t;
  28. int num=t;
  29. for(int i=head[u];~i;i=e[i].next)
  30. {
  31. int v=e[i].to;
  32. if(vis[v]) continue;
  33. q.push(v);
  34. pre[v]=u;
  35. vis[v]=true;
  36. while(num&&(num==col[u]||num==col[pre[u]]))
  37. num--;
  38. if(num)
  39. col[v]=num--;
  40. else
  41. col[v]=++tmp;
  42. }
  43. t=tmp;
  44. }
  45. }
  46. void init()
  47. {
  48. tol=0;
  49. memset(head,-1,sizeof(head));
  50. memset(in,0,sizeof(in));
  51. }
  52. void add(int u,int v)
  53. {
  54. e[tol].to=v;
  55. e[tol].next=head[u];
  56. head[u]=tol++;
  57. }
  58.  
  59. int main()
  60. {
  61. int n,u,v;
  62. scanf("%d",&n);
  63. init();
  64. for(int i=2;i<=n;i++)
  65. {
  66. scanf("%d%d",&u,&v);
  67. add(u,v);
  68. add(v,u);
  69. in[u]++;
  70. in[v]++;
  71. }
  72. int pos;
  73. for(int i=1;i<=n;i++)
  74. {
  75. if(in[i]==1)
  76. {
  77. pos=i;
  78. break;
  79. }
  80. }
  81. BFS(pos);
  82. int ans=0;
  83. for(int i=1;i<=n;i++)
  84. ans=max(ans,col[i]);
  85. printf("%d\n",ans);
  86. for(int i=1;i<=n;i++)
  87. printf("%d ",col[i]);
  88. return 0;
  89. }

Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)【A,B,C】的更多相关文章

  1. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)

    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...

  2. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League

    地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...

  3. 树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E

    http://codeforces.com/contest/782/problem/E 题目大意: 有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取 ...

  4. 2-sat Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D

    http://codeforces.com/contest/782/problem/D 题意: 每个队有两种队名,问有没有满足以下两个条件的命名方法: ①任意两个队的名字不相同. ②若某个队 A 选用 ...

  5. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab

    地址:http://codeforces.com/contest/782/problem/E 题目: E. Underground Lab time limit per test 1 second m ...

  6. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons

    地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per ...

  7. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed

    地址:http://codeforces.com/contest/782/problem/B 题目: B. The Meeting Place Cannot Be Changed time limit ...

  8. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A. Andryusha and Socks

    地址:http://codeforces.com/contest/782/problem/A 题目: A. Andryusha and Socks time limit per test 2 seco ...

  9. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)A模拟 B三分 C dfs D map

    A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. 【题解】quake

    [题解]\(quake\) 题目大意 我们共有报酬\(f\)元,一条边有它的价值\(w_i\),有它的建造时间\(t_i\).要求建一些边,生成一颗树.求最大的利润率. 数据范围 \(n\le 400 ...

  2. testng ITestListener使用

    ITestListener适用场景 当使用testng执行测试时,我们常会想在某个阶段做一些特别的处理,比如:测试成功结束后,测试失败后,跳过某个脚本后,全部脚本执行完毕后.要想达成这个目标,我们需要 ...

  3. 【栈】日志分析(BSOJ2981)

    Description M海运公司最近要对旗下仓库的货物进出情况进行统计.目前他们所拥有的唯一记录就是一个记录集装箱进出情况的日志.该日志记录了两类操作:第一类操作为集装箱入库操作,以及该次入库的集装 ...

  4. MSSQL2005外网IP的1433端口开启方法

    打开SQL Server Configuration Manager,在SQL server配置管理器展开SQL server 2005网络配置-->SQLEXPRESS 的协议-->双击 ...

  5. 高通MSM8255 GPS 调试分析&&Android系统之Broadcom GPS 移植【转】

    本文转载自:http://blog.csdn.net/gabbzang/article/details/12063031 http://blog.csdn.NET/dwyane_zhang/artic ...

  6. WCF异常处理

    [读书笔记] 在进行分布式应用的异常处理时需要解决和考虑的基本要素: 异常的封装:服务端抛出的异常如何序列化传递到客户端 敏感信息的屏蔽:抛出的异常往往包含一些敏感的信息,直接将服务操作执行过程抛出的 ...

  7. Linux-Yum服务器搭建

    Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器.基于RPM包管理,能够从指定的服务器自动下载 ...

  8. tensorflow实现svm iris二分类——本质上在使用梯度下降法求解线性回归(loss是定制的而已)

    iris二分类 # Linear Support Vector Machine: Soft Margin # ---------------------------------- # # This f ...

  9. C#SocketAsyncEventArgs实现高效能多并发TCPSocket通信 (服务器实现)

    http://freshflower.iteye.com/blog/2285272 想着当初到处找不到相关资料来实现.net的Socket通信的痛苦与心酸, 于是将自己写的代码公布给大家, 让大家少走 ...

  10. [acm]HDOJ 2673 shǎ崽 OrOrOrOrz

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=2673 拍两次序,交替输出 #include<iostream> #include< ...