SRM 398 DIV2 [250]
2008-04-26 13:46
218 查看
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<iostream>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<algorithm>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<vector>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
class MinDifference...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int closestElements(int A0,int X,int Y,int M,int n)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
vector<int> ivec(n);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
vector<int>::iterator iter=ivec.begin();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*iter++=A0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (;iter!=ivec.end();++iter)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*iter=(*(iter-1)*X+Y)%M;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sort(ivec.begin(),iter);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iter=ivec.begin()+1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int min=*iter-*(iter-1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (;iter!=ivec.end();++iter)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (*iter-*(iter-1)<min) min=*iter-*(iter-1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return min;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
Problem Statement | ||||||||||||
You are given numbers A0, X, Y, M and n. Generate a list A of length n according to the following recurrence relation: A[0] = A0 A[i] = (A[i - 1] * X + Y) MOD M, for 0 < i < n Return the minimal absolute difference between any two elements of A. | ||||||||||||
Definition | ||||||||||||
| ||||||||||||
Constraints | ||||||||||||
- | A0, X, Y, M will each be between 1 and 10000, inclusive. | |||||||||||
- | n will be between 2 and 10000, inclusive. | |||||||||||
Examples | ||||||||||||
0) | ||||||||||||
| ||||||||||||
1) | ||||||||||||
| ||||||||||||
2) | ||||||||||||
| ||||||||||||
3) | ||||||||||||
| ||||||||||||
4) | ||||||||||||
| ||||||||||||
5) | ||||||||||||
|
相关文章推荐
- SRM 597 DIV2 250
- SRM 594 DIV1 250
- SRM 595 DIV1 250
- SRM 397 DIV 2 [250]
- TopCoder 250 points 17-SRM 152 DIV 1 106.51/250 42.60%
- SRM 577 250 DIV2
- SRM 575 250 DIV2
- topcoder SRM 543 div2 250
- SRM 667 DIV 2 PointDistance 250-point
- 小朋友学TopCoder(7):SRM726 DIV2 250-point
- 最小公倍数 SRM 661 Div1 250: MissingLCM
- TopCoder 250 points 28-SRM 157 DIV 2 185.60/250 74.24%
- TopCoder 250 points 8-SRM 147 DIV 2 176.36/250 70.54%
- TopCoder 250 points 18-SRM 152 DIV 2 167.05/250 66.82%
- topcoder SRM 541 div2 250
- TopCoder SRM 612 DIV1 250 EmoticonsDiv1
- 【topcoder SRM 652 DIV2 250】ValueOfString
- TopCoder 250 points 10-SRM 148 DIV 2 167.20/250 66.88%
- TopCoder 250 points 13-SRM 150 DIV 1 82.63/250 33.05%
- TopCoder 250 points 14-SRM 150 DIV 2 86.25/250 34.50%