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 ...
随机推荐
- bzoj4025
首先我们要知道,怎么去维护一个是否是二分图 二分图的充要条件:点数>=2且无奇环 重点就是不存在奇环,怎么做呢 考虑随便维护一个图的生成树,不难发现,如果一条边加入后,形成奇环的话就不是二分图 ...
- WebService只能在本地使用,无法通过网络访问的解决办法
问题描述:WebService只能在本地使用,无法通过网络访问. 解决方案:在web.config的<system.web></system.web>中间加入如下配置节内容: ...
- 如何在Asp.Net WebApi接口中,验证请求参数中是否携带token标识!
[BasicAuthentication] public abstract class ApiControllerBase : ApiController { #region Gloal Proper ...
- codevs 1197 Vigenère密码
开始做NOIP啦.. #include<iostream> #include<cstdio> #include<cstring> #include<algor ...
- Raphael 目标点沿路径不断移动
<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8" ...
- Liunx 配置IDE
如果你还没装编译环境或自己不确定装没装,不妨先执行 sudo apt-get install build-essential 如果你已经了解一些 vim 的知识,而且想用它来编辑源代码,那么我们不妨装 ...
- 一天一个Java基础——泛型
这学期的新课——设计模式,由我仰慕已久的老师传授,可惜思维过快,第一节就被老师挑中上去敲代码,自此在心里烙下了阴影,都是Java基础欠下的债 这学期的新课——算法设计与分析,虽老师不爱与同学互动式的讲 ...
- 【转】linux中waitpid及wait的用法
原文网址:http://www.2cto.com/os/201203/124851.html wait(等待子进程中断或结束) 表头文件 #include<sys/types.h> ...
- win10 enterprise 10240激活:
win10 enterprise 10240激活: 以管理员命令:slmgr /upkslmgr /ipk NPPR9-FWDCX-D2C8J-H872K-2YT43slmgr /skms kms.x ...
- mysql SQL_MODE设置
1.1. SQL_MODE设置 在生产环境中强烈建议将这个值设置为严格模式,这样有些问题可以在数据库的设计和开发阶段就能实现,而如果在生产环境下运行数据库后发现这类问题,那么修改的代价将变得十分巨 ...