CodeForces 589D Boulevard (数学,相遇)
题意:给定 n 个的在 x 轴上的坐标,和开始时间,结束坐标,从起点向终点走,如果和其他人相遇,就互相打招乎,问你每人打招乎的次数。
析:其实这一个数学题,由于 n 比较小,我们就可以两两暴力,这两个我们先让他们同时出现,也就是让先出现的,先走着,走到和后来的同一时间,
然后判方向,如果方向不是相对,或者是坐标一样,那么就是不可能相遇,然后如果是相遇,那么就可以相对速度来算,先两者的距离,再算相遇的时间,
最后判不是走过终点了即可。
代码如下:
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include <cstdio>
- #include <string>
- #include <cstdlib>
- #include <cmath>
- #include <iostream>
- #include <cstring>
- #include <set>
- #include <queue>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <cctype>
- #include <stack>
- using namespace std ;
- typedef long long LL;
- typedef pair<int, int> P;
- const int INF = 0x3f3f3f3f;
- const double inf = 0x3f3f3f3f3f3f;
- const double PI = acos(-1.0);
- const double eps = 1e-8;
- const int maxn = 1e3 + 5;
- const int mod = 1e9 + 7;
- const char *mark = "+-*";
- const int dr[] = {-1, 0, 1, 0};
- const int dc[] = {0, 1, 0, -1};
- int n, m;
- inline bool is_in(int r, int c){
- return r >= 0 && r < n && c >= 0 && c < m;
- }
- struct node{
- LL s, f, t;
- };
- node a[maxn];
- int ans[maxn];
- int main(){
- while(scanf("%d", &n) == 1){
- memset(ans, 0, sizeof(ans));
- for(int i = 0; i < n; ++i)
- scanf("%I64d %I64d %I64d", &a[i].t, &a[i].s, &a[i].f);
- for(int i = 0; i < n; ++i){
- int li = a[i].s <= a[i].f ? 1 : -1;
- for(int j = i+1; j < n; ++j){
- int lj = a[j].s <= a[j].f ? 1 : -1;
- node u = a[i], v = a[j];
- if(u.t < v.t) u.s += (LL)(v.t-u.t) * li;//匹配时间
- else if(u.t > v.t) v.s += (LL)(u.t-v.t) * lj;
- if((u.s - u.f) * (a[i].s - a[i].f) < 0) continue;
- if((v.s - v.f) * (a[j].s - a[j].f) < 0) continue;
- if(u.s == v.s) ++ans[i], ++ans[j];//判断是不是能相遇
- else{
- if(li * lj > 0) continue;
- if(u.s < v.s && li == -1) continue;
- if(u.s > v.s && li == 1) continue;
- LL tt = abs(u.s-v.s);
- if(tt & 1){
- LL ti = tt / 2;
- if(li * (u.s + ti * li - u.f) >= 0) continue;
- if(lj * (v.s + ti * lj - v.f) >= 0) continue;
- ++ans[i], ++ans[j];
- }
- else{
- LL ti = tt / 2;
- if(li * (u.s + ti * li - u.f) > 0) continue;
- if(lj * (v.s + ti * lj - v.f) > 0) continue;
- ++ans[i], ++ans[j];
- }
- }
- }
- }
- for(int i = 0; i < n; ++i){
- if(i) putchar(' ');
- printf("%d", ans[i]);
- }
- printf("\n");
- }
- return 0;
- }
CodeForces 589D Boulevard (数学,相遇)的更多相关文章
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- CodeForces - 589D
题目链接:http://codeforces.com/problemset/problem/589/D 思路:将每个人的信息转化为自变量为时间因变量为位置的一元方程.再一个个判断是否相遇. 若两人同向 ...
- CodeForces - 589D —(思维题)
Welcoming autumn evening is the best for walking along the boulevard and npeople decided to do so. T ...
- CodeForces 173A Rock-Paper-Scissors 数学
Rock-Paper-Scissors 题目连接: http://codeforces.com/problemset/problem/173/A Description Nikephoros and ...
- Success Rate CodeForces - 807C (数学+二分)
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces ...
- Codeforces 622F 「数学数论」「数学规律」
题意: 给定n和k,求 1 ≤ n ≤ 109, 0 ≤ k ≤ 106 思路: 题目中给的提示是对于给定的k我们可以求出一个最高次为k+1的关于n的通项公式. 根据拉格郎日插值法,我们可以通过k+2 ...
- CodeForces 709B Checkpoints (数学,最短路)
题意:给定你的坐标,和 n 个点,问你去访问至少n-1个点的最短路是多少. 析:也是一个很简单的题,肯定是访问n-1个啊,那么就考虑从你的位置出发,向左访问和向右访问总共是n-1个,也就是说你必须从1 ...
- CodeForces 706A Beru-taxi (数学计算,水题)
题意:给定一个固定位置,和 n 个点及移动速度,问你这些点最快到固定点的时间. 析:一个一个的算距离,然后算时间. 代码如下: #pragma comment(linker, "/STACK ...
- 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 ...
随机推荐
- 真心崩溃了,oracle安装完成后居然没有tnsnames.ora和listener.ora文件
problem: oracle 11 r2 64位安装完成后NETWORK/ADMIN目录下居然没有tnsnames.ora和listener.ora文件 solution: 问题是之前安装了另 ...
- LA 3516 (计数 DP) Exploring Pyramids
设d(i, j)为连续子序列[i, j]构成数的个数,因为遍历从根节点出发最终要回溯到根节点,所以边界情况是:d(i, i) = 1; 如果s[i] != s[j], d(i, j) = 0 假设第一 ...
- BZOJ3850: ZCC Loves Codefires
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题解:类似于国王游戏,推一下相邻两个元素交换的条件然后排个序就可以了. 代码: #inc ...
- Asp.Net连接Mysql报错Out of sync with server
Asp.Net连接Mysql报错Out of sync with server 原因:程序引用的MySql.Data.dll版本高于服务器版本 解决:下载一个低版本的MySql.Data.dll,项目 ...
- 无线端不响应键盘事件(keydown,keypress,keyup)
今天在项目时,在android手机上使用输入法的智能推荐的词的话,不会触发keyup事件,一开始想到在focus时使用一个定时器,每隔100ms检测输入框的值是否发生了改变,如果改变了就作对应的处理, ...
- Library cache lock/pin详解
Library cache lock/pin 一.概述 ---本文是网络资料加metalink 等整理得来一个实例中的library cache包括了不同类型对象的描述,如:游标,索引,表,视图,过程 ...
- 【转】VS2012编译出来的程序,在XP上运行,出现“.exe 不是有效的 win32 应用程序” “not a valid win32 application”
原文网址:http://www.cnblogs.com/Dageking/archive/2013/05/15/3079394.html VS2012编译出来的程序,在XP上运行,出现“.exe 不是 ...
- 【转】linux下a.out >outfile 2>&1重定向问题
原文网址:http://blog.chinaunix.net/uid-25909722-id-2912890.html 转自:http://blog.chinaunix.net/space.php?u ...
- Ruby 文件处理
#r read, #w write, #a append, #r+ 读写方式 从文件的头位置开始读取或写入, #w+ 读写方式,如果文件已存在清空该文件,不存在就创建一个新的文件, #a+ 如果文件存 ...
- hashtable,hashMap,vector和ArrayList
关于vector,ArrayList,hashMap和hashtable之间的区别 vector和ArrayList: 线程方面: vector是旧的,是线程安全的 ArrayList是java ...