题意:给定 n 个的在 x 轴上的坐标,和开始时间,结束坐标,从起点向终点走,如果和其他人相遇,就互相打招乎,问你每人打招乎的次数。

析:其实这一个数学题,由于 n 比较小,我们就可以两两暴力,这两个我们先让他们同时出现,也就是让先出现的,先走着,走到和后来的同一时间,

然后判方向,如果方向不是相对,或者是坐标一样,那么就是不可能相遇,然后如果是相遇,那么就可以相对速度来算,先两者的距离,再算相遇的时间,

最后判不是走过终点了即可。

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <stack>
  15. using namespace std ;
  16.  
  17. typedef long long LL;
  18. typedef pair<int, int> P;
  19. const int INF = 0x3f3f3f3f;
  20. const double inf = 0x3f3f3f3f3f3f;
  21. const double PI = acos(-1.0);
  22. const double eps = 1e-8;
  23. const int maxn = 1e3 + 5;
  24. const int mod = 1e9 + 7;
  25. const char *mark = "+-*";
  26. const int dr[] = {-1, 0, 1, 0};
  27. const int dc[] = {0, 1, 0, -1};
  28. int n, m;
  29. inline bool is_in(int r, int c){
  30. return r >= 0 && r < n && c >= 0 && c < m;
  31. }
  32. struct node{
  33. LL s, f, t;
  34. };
  35. node a[maxn];
  36. int ans[maxn];
  37.  
  38. int main(){
  39. while(scanf("%d", &n) == 1){
  40. memset(ans, 0, sizeof(ans));
  41. for(int i = 0; i < n; ++i)
  42. scanf("%I64d %I64d %I64d", &a[i].t, &a[i].s, &a[i].f);
  43. for(int i = 0; i < n; ++i){
  44. int li = a[i].s <= a[i].f ? 1 : -1;
  45. for(int j = i+1; j < n; ++j){
  46. int lj = a[j].s <= a[j].f ? 1 : -1;
  47. node u = a[i], v = a[j];
  48. if(u.t < v.t) u.s += (LL)(v.t-u.t) * li;//匹配时间
  49. else if(u.t > v.t) v.s += (LL)(u.t-v.t) * lj;
  50. if((u.s - u.f) * (a[i].s - a[i].f) < 0) continue;
  51. if((v.s - v.f) * (a[j].s - a[j].f) < 0) continue;
  52.  
  53. if(u.s == v.s) ++ans[i], ++ans[j];//判断是不是能相遇
  54. else{
  55. if(li * lj > 0) continue;
  56. if(u.s < v.s && li == -1) continue;
  57. if(u.s > v.s && li == 1) continue;
  58. LL tt = abs(u.s-v.s);
  59. if(tt & 1){
  60. LL ti = tt / 2;
  61. if(li * (u.s + ti * li - u.f) >= 0) continue;
  62. if(lj * (v.s + ti * lj - v.f) >= 0) continue;
  63. ++ans[i], ++ans[j];
  64. }
  65. else{
  66. LL ti = tt / 2;
  67. if(li * (u.s + ti * li - u.f) > 0) continue;
  68. if(lj * (v.s + ti * lj - v.f) > 0) continue;
  69. ++ans[i], ++ans[j];
  70. }
  71. }
  72. }
  73. }
  74. for(int i = 0; i < n; ++i){
  75. if(i) putchar(' ');
  76. printf("%d", ans[i]);
  77. }
  78. printf("\n");
  79. }
  80. return 0;
  81. }

CodeForces 589D Boulevard (数学,相遇)的更多相关文章

  1. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  2. CodeForces - 589D

    题目链接:http://codeforces.com/problemset/problem/589/D 思路:将每个人的信息转化为自变量为时间因变量为位置的一元方程.再一个个判断是否相遇. 若两人同向 ...

  3. CodeForces - 589D —(思维题)

    Welcoming autumn evening is the best for walking along the boulevard and npeople decided to do so. T ...

  4. CodeForces 173A Rock-Paper-Scissors 数学

    Rock-Paper-Scissors 题目连接: http://codeforces.com/problemset/problem/173/A Description Nikephoros and ...

  5. Success Rate CodeForces - 807C (数学+二分)

    You are an experienced Codeforces user. Today you found out that during your activity on Codeforces ...

  6. Codeforces 622F 「数学数论」「数学规律」

    题意: 给定n和k,求 1 ≤ n ≤ 109, 0 ≤ k ≤ 106 思路: 题目中给的提示是对于给定的k我们可以求出一个最高次为k+1的关于n的通项公式. 根据拉格郎日插值法,我们可以通过k+2 ...

  7. CodeForces 709B Checkpoints (数学,最短路)

    题意:给定你的坐标,和 n 个点,问你去访问至少n-1个点的最短路是多少. 析:也是一个很简单的题,肯定是访问n-1个啊,那么就考虑从你的位置出发,向左访问和向右访问总共是n-1个,也就是说你必须从1 ...

  8. CodeForces 706A Beru-taxi (数学计算,水题)

    题意:给定一个固定位置,和 n 个点及移动速度,问你这些点最快到固定点的时间. 析:一个一个的算距离,然后算时间. 代码如下: #pragma comment(linker, "/STACK ...

  9. Divide Candies CodeForces - 1056B (数学)

    Arkady and his friends love playing checkers on an n×nn×n field. The rows and the columns of the fie ...

随机推荐

  1. 真心崩溃了,oracle安装完成后居然没有tnsnames.ora和listener.ora文件

    problem: oracle  11  r2  64位安装完成后NETWORK/ADMIN目录下居然没有tnsnames.ora和listener.ora文件 solution: 问题是之前安装了另 ...

  2. LA 3516 (计数 DP) Exploring Pyramids

    设d(i, j)为连续子序列[i, j]构成数的个数,因为遍历从根节点出发最终要回溯到根节点,所以边界情况是:d(i, i) = 1; 如果s[i] != s[j], d(i, j) = 0 假设第一 ...

  3. BZOJ3850: ZCC Loves Codefires

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题解:类似于国王游戏,推一下相邻两个元素交换的条件然后排个序就可以了. 代码: #inc ...

  4. Asp.Net连接Mysql报错Out of sync with server

    Asp.Net连接Mysql报错Out of sync with server 原因:程序引用的MySql.Data.dll版本高于服务器版本 解决:下载一个低版本的MySql.Data.dll,项目 ...

  5. 无线端不响应键盘事件(keydown,keypress,keyup)

    今天在项目时,在android手机上使用输入法的智能推荐的词的话,不会触发keyup事件,一开始想到在focus时使用一个定时器,每隔100ms检测输入框的值是否发生了改变,如果改变了就作对应的处理, ...

  6. Library cache lock/pin详解

    Library cache lock/pin 一.概述 ---本文是网络资料加metalink 等整理得来一个实例中的library cache包括了不同类型对象的描述,如:游标,索引,表,视图,过程 ...

  7. 【转】VS2012编译出来的程序,在XP上运行,出现“.exe 不是有效的 win32 应用程序” “not a valid win32 application”

    原文网址:http://www.cnblogs.com/Dageking/archive/2013/05/15/3079394.html VS2012编译出来的程序,在XP上运行,出现“.exe 不是 ...

  8. 【转】linux下a.out >outfile 2>&1重定向问题

    原文网址:http://blog.chinaunix.net/uid-25909722-id-2912890.html 转自:http://blog.chinaunix.net/space.php?u ...

  9. Ruby 文件处理

    #r read, #w write, #a append, #r+ 读写方式 从文件的头位置开始读取或写入, #w+ 读写方式,如果文件已存在清空该文件,不存在就创建一个新的文件, #a+ 如果文件存 ...

  10. hashtable,hashMap,vector和ArrayList

    关于vector,ArrayList,hashMap和hashtable之间的区别 vector和ArrayList:  线程方面:  vector是旧的,是线程安全的  ArrayList是java ...