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 ...
随机推荐
- 宏HASH_SEARCH
/********************************************************************//** Looks for a struct in a ha ...
- Android平台调用WebService详解
上篇文章已经对Web Service及其相关知识进行了介绍(Android开发之WebService介绍 ),相信有的朋友已经忍耐不住想试试在Android应用中调用Web Service.本文将通过 ...
- WebView线性进度条
参考:http://www.cnblogs.com/hubli/p/4835549.html APP会跳转网页时候,请参考:http://blog.csdn.net/raphael55/article ...
- $http POST 转字符串
- 门户网站架构Nginx+Apache+MySQL+PHP+Memcached+Squid
服务器的大用户量的承载方案 一.前言二.编译安装三. 安装MySQL.memcache四. 安装Apache.PHP.eAccelerator.php-memcache五. 安装Squid六.后记 一 ...
- 【大数模板】C++大数类 大数模板
分别使用C++中的运算符重载的方法来实现大数之间的数学运算,包括加法.减法.乘法.除法.n次方.取模.大小比较.赋值以及输入流.输出流的重载. 感觉很麻烦... [代码] #include<io ...
- 动态加载so文件
在开发过程中,经常会用到第三方库,比如地图.视频.文档编辑.图表之类.依赖这些库,需要添加其SDK,有时需要用到jni层的So文件,比如百度地图等. 那么问题来了,如果两个不同的库之间的so文件发生冲 ...
- Android01--开发环境搭建
1 -- 下载所需软件 Android SDK下载地址:http://developer.android.com/sdk/index.html Eclipse下载地址:http://www.eclip ...
- HDU 5745 La Vie en rose
La Vie en rose Time Limit: 14000/7000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- Delphi 利用TComm组件 Spcomm 实现串行通信
Delphi 利用TComm组件 Spcomm 实现串行通信 摘要:利用Delphi开发工业控制系统软件成为越来越多的开发人员的选择,而串口通信是这个过程中必须解决的问题之一.本文在对几种常用串口通信 ...