Contest Duration: - (local time) (100 minutes) Back to Home
Official

## A - T-shirt Editorial by en_translator

If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar to problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
「競プロ典型 90 問」(Typical 90 Problems of Competitive Programming) (https://atcoder.jp/contests/typical90) is a collection of typical 90 competitive programming problems; unfortunately, currently the problem statements are all Japanese.
「C++入門 AtCoder Programming Guide for beginners (APG4b)」(https://atcoder.jp/contests/APG4b) is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.

You can find the answer in the following flow.

• If $$X \le A$$, then the answer is $$1$$;
• otherwise, if $$X \le B$$, then the answer is $$\frac{C}{B-A}$$;
• otherwise, the answer is $$0$$.

This can be implemented with if statements.

Be careful of how to output real numbers. Especially, your answer may be judged to be a wrong answer due to the lack of digits to be output.
The way to handle this issue varies language to language. For example, one of the solutions in C++ is to use printf. In the sample code, the output format specifies that $$12$$ digits after the decimal point should be printed.

Sample code (C++):

#include<bits/stdc++.h>

using namespace std;

int main(){
int a,b,c,x;
cin >> a >> b >> c >> x;

if(x<=a){printf("%.12lf\n",1.0);}
else if(x<=b){
double res=c;
res/=(b-a);
printf("%.12lf\n",res);
}
else{
printf("%.12lf\n",0.0);
}
return 0;
}


posted:
last update: