ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1904. The Lessons of the Past

so simple, but WA4?
Posted by ASK 26 Jan 2014 01:04
Since k <= 10 and |ai| ≤ 1000 the largest answer is 10001: let use -11000..11000 to be sure.

Since the end of each segment is an integer such that on one side inequality holds and on the other it is not, the solution is trivial: just find all such points. Still the following program gives WA4. Any hint?

#define I(x) int x; cin >> x
#define FA(i,c) for(auto& i: c)
#define FE(i,a,b) for(int i = (a); i <= (b); ++i)
typedef vector<int> V;

V a;
bool in(double x){
  FA(ai,a) x = fabs(x-ai);
  return x < 1;
}

int main(){
  I(k); a.resize(k); FA(ai,a) cin >> ai;
  V b;
  FE(ix,-11000,11000)
    if(in(ix-0.1) != in(ix+0.1))
      b.push_back(ix);
  cout << b.size()/2 << endl;
  for(size_t i = 0; i < b.size(); i += 2)
    cout << b[i] << ' ' << b[i+1] << endl;
}
Re: so simple, but WA4?
Posted by ASK 27 Jan 2014 16:20
<https://en.wikipedia.org/wiki/Line_segment>:
a line segment is a part of a line that is bounded by two distinct end points

In this problem, the end points of a "segment" are not required to be distinct (first occurrence in test 4).