HDU 5626 Clarke and points
2016-02-14 13:47
267 查看
Clarke and points
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 127 Accepted Submission(s): 98
[align=left]Problem Description[/align]
Clarke is a patient with multiple personality disorder. One day he turned into a learner of geometric.
He did a research on a interesting distance called Manhattan Distance. The Manhattan Distance between pointA(xA,yA)
and point B(xB,yB)
is |xA−xB|+|yA−yB|.
Now he wants to find the maximum distance between two points of
n
points.
[align=left]Input[/align]
The first line contains a integer
T(1≤T≤5),
the number of test case.
For each test case, a line followed, contains two integers
n,seed(2≤n≤1000000,1≤seed≤109),
denotes the number of points and a random seed.
The coordinate of each point is generated by the followed code.
```
long long seed;
inline long long rand(long long l, long long r) {
static long long mo=1e9+7, g=78125;
return l+((seed*=g)%=mo)%(r-l+1);
}
// ...
cin >> n >> seed;
for (int i = 0; i < n; i++)
x[i] = rand(-1000000000, 1000000000),
y[i] = rand(-1000000000, 1000000000);
```
[align=left]Output[/align]
For each test case, print a line with an integer represented the maximum distance.
[align=left]Sample Input[/align]
2 3 233 5 332
[align=left]Sample Output[/align]
1557439953 1423870062
#include<iostream> #include<cmath> #include<algorithm> using namespace std; typedef long long ll; const int maxn = 1000000 + 10; struct point{ ll x, y; }a[maxn]; ll seed; inline long long Rand(long long l,long long r) { static long long mo=1e9+7, g=78125; return l+((seed*=g)%=mo)%(r-l+1); } int main(){ int t,n; cin>>t; while(t--){ cin>>n>>seed; for(int i = 0; i < n; i++){ a[i].x = Rand(-1000000000, 1000000000), a[i].y = Rand(-1000000000, 1000000000); } ll xMax = a[0].x + a[0].y, xMin = a[0].x + a[0].y; ll yMax = a[0].x - a[0].x, yMin = a[0].x - a[0].y; for(int i = 1; i < n; i++){ ll ax = a[i].x + a[i].y; ll in = a[i].x - a[i].y; xMax = max(xMax, ax); xMin = min(xMin, ax); yMax = max(yMax, in); yMin = min(yMin, in); } ll ans = max(abs(xMax - xMin), abs(yMax - yMin)); cout<<ans<<endl; } return 0; }
相关文章推荐
- hdu 1025 dp+二分 模板
- ulimit
- Windows server 2008 R2远程桌面终端连接数的破解
- Android中微信抢红包插件原理解析及开发思路
- Android实现微信自动抢红包的程序
- 放肆地使用UIBezierPath和CAShapeLayer画各种图形
- android studio 获取sha1和md5值
- 关于cocoapods的一些坑
- iOS9支付完成无法获取回调
- POJ 2926 Requirements
- R语言实现关联规则与推荐算法(学习笔记)
- Android 动画之ScaleAnimation应用详解
- 十步完全理解 SQL
- 关于NPOI导入导出
- Linux学习第一天
- 恭喜发财! -- 手把手教你仿造一个qq下拉抢红包 Android自定义view
- 恭喜发财! -- 手把手教你仿造一个qq下拉抢红包 Android自定义view
- CMD常用命令
- Android开发涉及到的设计模式
- 新手必看!教你从零开始制作四轴飞行器!(zhuan)