src
stringlengths 95
64.6k
| complexity
stringclasses 7
values | problem
stringlengths 6
50
| from
stringclasses 1
value |
---|---|---|---|
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
System.out.println(n/2*3);
}
}
| constant | 84_A. Toy Army | CODEFORCES |
import java.util.Scanner;
public class A_Toy_Army {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner entrada = new Scanner(System.in);
while(entrada.hasNextInt())
{
int n = entrada.nextInt();
System.out.println(n+(n/2));
}
}
}
| constant | 84_A. Toy Army | CODEFORCES |
import java.io.*;
import java.util.*;
public class A{
private BufferedReader in;
private StringTokenizer st;
void solve() throws IOException{
int n = nextInt();
System.out.println(3 * n/2);
}
A() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
eat("");
solve();
}
private void eat(String str) {
st = new StringTokenizer(str);
}
String next() throws IOException {
while (!st.hasMoreTokens()) {
String line = in.readLine();
if (line == null) {
return null;
}
eat(line);
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static void main(String[] args) throws IOException {
new A();
}
int gcd(int a,int b){
if(b>a) return gcd(b,a);
if(b==0) return a;
return gcd(b,a%b);
}
}
| constant | 84_A. Toy Army | CODEFORCES |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n,b = 0;
n=in.nextInt();
if (n%2==0) {
b=n+n/2;
System.out.println(b);
}
}
}
| constant | 84_A. Toy Army | CODEFORCES |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
System.out.println(n * 6 / 4);
}
} | constant | 84_A. Toy Army | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ToyArmy {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
System.out.println(n / 2 * 3);
}
}
| constant | 84_A. Toy Army | CODEFORCES |
import java.util.Scanner;
public class p84a {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
System.out.println((n/2)*3);
}
}
| constant | 84_A. Toy Army | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;
public class sample {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
System.out.println(n+n/2);
}
} | constant | 84_A. Toy Army | CODEFORCES |
import java.io.PrintWriter;
import java.util.Locale;
import java.util.Scanner;
public class A {
public static void main (String[] args){
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
out.printf(Locale.US, "%d", n/2*3);
out.close();
}
}
| constant | 84_A. Toy Army | CODEFORCES |
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Saransh
*/
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try
{
Parserdoubt pd=new Parserdoubt(System.in);
//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=pd.nextInt();
PrintWriter pw=new PrintWriter(System.out);
pw.println((n*3)/2);
pw.flush();
}
catch(Exception e)
{}
}
}
class Parserdoubt
{
final private int BUFFER_SIZE = 1 << 17;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Parserdoubt(InputStream in)
{
din = new DataInputStream(in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String nextString() throws Exception
{
StringBuffer sb=new StringBuffer("");
byte c = read();
while (c <= ' ') c = read();
do
{
sb.append((char)c);
c=read();
}while(c>' ');
return sb.toString();
}
public char nextChar() throws Exception
{
byte c=read();
while(c<=' ') c= read();
return (char)c;
}
public int nextInt() throws Exception
{
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = c == '-';
if (neg) c = read();
do
{
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg) return -ret;
return ret;
}
public long nextLong() throws Exception
{
long ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = c == '-';
if (neg) c = read();
do
{
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg) return -ret;
return ret;
}
private void fillBuffer() throws Exception
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws Exception
{
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
} | constant | 84_A. Toy Army | CODEFORCES |
import java.io.IOException;
import java.util.Scanner;
public class A {
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println((2*n) - (n/2));
}
}
| constant | 84_A. Toy Army | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author Mostafa
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
System.out.println((n/2) *3);
}
}
| constant | 84_A. Toy Army | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* May 13, 2011
* @author parisel
*/
public class ToyArmy {
int N;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] tok;
String s;
private String[] getTok() throws IOException {return br.readLine().split(" ");}
private int getInt() throws IOException {return Integer.valueOf(br.readLine());}
private int[] getInt(int N) throws IOException {
int[] data= new int[N]; tok= br.readLine().split(" ");
for (int i=0; i<N; i++) data[i]= Integer.valueOf(tok[i]);
return data;
}
public void solve() throws IOException {
int i=0, j=0;
N= getInt();
long kill= (3*N)/2;
System.out.printf("%d\n", kill);
}
public static void main(String[] args) throws IOException {
new ToyArmy().solve();
}
}
| constant | 84_A. Toy Army | CODEFORCES |
import java.util.*;
import java.lang.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception{
FastReader sc=new FastReader();
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
int n=sc.nextInt();
HashMap<String,Integer> map=new HashMap<String,Integer>();
for(int i=0;i<n;i++) {
map.put(sc.next(), 1);
}
ArrayList<String> list=new ArrayList<String>();
int count=0;
if(!map.containsKey("purple")) {
count++;
list.add("Power");
}
if(!map.containsKey("green")) {
count++;
list.add("Time");
}
if(!map.containsKey("blue")) {
count++;
list.add("Space");
}
if(!map.containsKey("orange")) {
count++;
list.add("Soul");
}
if(!map.containsKey("red")) {
count++;
list.add("Reality");
}
if(!map.containsKey("yellow")) {
count++;
list.add("Mind");
}System.out.println(count);
for(String s:list) {
System.out.println(s);
}
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} | constant | 987_A. Infinity Gauntlet | CODEFORCES |
import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskD solver = new TaskD();
solver.solve(1, in, out);
out.close();
}
}
class TaskD {
public void solve(int testNumber, Scanner in, PrintWriter out) {
String[] str = in.nextLine().split(" ");
int a = Integer.parseInt(str[0]);
int v = Integer.parseInt(str[1]);
str = in.nextLine().split(" ");
int l = Integer.parseInt(str[0]);
int d = Integer.parseInt(str[1]);
int w = Integer.parseInt(str[2]);
double minTime = 0.;
if (w >= v) {
minTime = getTimeAfterSign(0, v, l, a);
out.format(Locale.US, "%.6f", minTime);
return;
}
double whenGetSpeedWPath = (w * w) / (2. * a);
if (whenGetSpeedWPath >= d) {
double time = Math.sqrt((2.0 * d) / a);
minTime = time + getTimeAfterSign(a * time, v, l - d, a);
} else {
double stopPath = (v * v - w * w) / (2. * a);
double vMaxPath = (v * v) / (2. * a);
if (stopPath + vMaxPath > d) {
// double topSpeed = (Math.sqrt(2. * a * d) + w) / 2;
// minTime = (topSpeed / a) + (topSpeed - w) / a + getTimeAfterSign(w, v, l - d, a);
double topSpeed = Math.sqrt((2. * a * d + w * w) / 2);
minTime = (2. * topSpeed - w) / a + getTimeAfterSign(w, v, l - d, a);
} else {
double stopTime = (v - w) / (a + 0.);
double getMaxTime = v / (a + 0.);
double maxTime = (d - (stopPath + vMaxPath)) / v;
minTime = stopTime + getMaxTime + maxTime + getTimeAfterSign(w, v, l - d, a);
}
}
out.format(Locale.US, "%.6f", minTime);
}
double getTimeAfterSign(double startSpeed, double maxSpeed, double path, int a) {
double maxSpeedTime = (maxSpeed - startSpeed) / a;
double maxSpeedPath = startSpeed * maxSpeedTime + (a * maxSpeedTime * maxSpeedTime) / 2;
if (maxSpeedPath > path) {
return (-startSpeed + Math.sqrt(startSpeed * startSpeed + 2 * a * path)) / a;
} else {
return maxSpeedTime + (path - maxSpeedPath) / maxSpeed;
}
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.Scanner;
public class Main{
static final double eps = 1e-10;
public static void main(String []args){
Scanner cin = new Scanner(System.in);
double a,v;
double l,d,w;
double time;
a = cin.nextDouble();
v = cin.nextDouble();
l = cin.nextDouble();
d = cin.nextDouble();
w = cin.nextDouble();
if(v < w + eps)
{
double t1 = v / a;
double len_bond = (v * v) / (2 * a);
if(len_bond + eps > l)
{
time = Math.sqrt(2 * l / a);
}
else
{
double t2 = (l - len_bond) / v;
time = t1 + t2;
}
System.out.println(time);
}
else
{
double len_bondv = (v * v) / (2 * a);
double len_bondw = (w * w) / (2 * a);
if(len_bondw + eps > d)
{
if(len_bondv + eps > l)
time = Math.sqrt(2 * l / a);
else{
double t1 = v / a;
double t2 = (l - len_bondv) / v;
time = t1 + t2;
}
}
else
{
double len_bonds = (v * v - w * w) / (2 * a);
if(len_bondv + len_bonds < d + eps)
time = v / a + (d - len_bondv - len_bonds) / v + (v - w) / a;
else
{
double f = Math.sqrt(d * a + w * w / 2);
time = f / a + (f - w) / a;
}
if (len_bonds + eps > l - d) {
double lv = Math.sqrt((l - d) * 2 * a + w * w);
time += (lv - w) / a;
} else {
time += (v - w) / a + (l - d - len_bonds) / v;
}
}
System.out.println(time);
}
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
public static void main(String args[]) throws IOException
{
new Main().run();
}
StreamTokenizer in;
PrintWriter out;
public void run() throws IOException
{
in =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
out = new PrintWriter(new OutputStreamWriter(System.out));
/*out = new PrintWriter(new FileWriter("output.txt"));
in =new StreamTokenizer(new BufferedReader(new FileReader("input.txt")));*/
solve();
out.flush();
}
public double nextInt() throws IOException
{
in.nextToken();
return in.nval;
}
public void solve() throws IOException
{
double a=nextInt(),v=nextInt(),l=nextInt(),d=nextInt(),w=nextInt();
double s=w*w/(2*a);
if(s>d || w>v)
{
double t=v*v/(2*a);
if(t>l)
{
double f=2*l/a;
out.print(String.format("%.10f",Math.sqrt(f)));
return;
}
double f=v/a;
double k=(l-t)/v;
out.print(String.format("%.10f",f+k));
return;
}
double t;
if((2*v*v-w*w)/(2*a)<d)
t=v/a+(v-w)/a+(d-(2*v*v-w*w)/(2*a))/v;
else
{
double v1=Math.sqrt((2*a*d+w*w)/2);
t=v1/a+(v1-w)/a;
}
double r=l-d;
double tr=(v*v-w*w)/(2*a);
if(tr>r)
{
double t1=(-w+Math.sqrt(w*w+2*a*r))/a;
out.print(String.format("%.10f",t+t1));
return;
}
r-=(v*v-w*w)/(2*a);
t+=(v-w)/a;
out.print(String.format("%.10f",t+r/v));
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.InputStreamReader;
import java.util.Scanner;
import java.io.IOException;
public class kresz {
public static double a;
public static double v;
public static double l;
public static double d;
public static double w;
public static double gyorsulut (double v1, double v2) { //v1 -> v2 mennyi utat tesz meg
return Math.abs((v2*v2-v1*v1)/(2*a));
}
public static double gyorsulido (double v1, double v2) { //v1 -> v2 mennyi idő
return Math.abs((v2-v1)/a);
}
public static void beolvas () throws IOException {
Scanner be = new Scanner (new InputStreamReader (System.in));
a = be.nextDouble();
v = be.nextDouble();
l = be.nextDouble();
d = be.nextDouble();
w = be.nextDouble();
be.close();
}
public static void main (String args[]) throws IOException {
beolvas();
double s = l; //hátralévő út
double t = 0; //eltelt idő
if (v <= w || Math.sqrt(2*a*d) <= w) { //nincs korlátozás
if (gyorsulut(0,v) > l) {
t+=gyorsulido(0, Math.sqrt(2*a*l));
s = 0;
}
else {
s-=gyorsulut(0,v);
t+=gyorsulido(0,v);
}
}
else {
//gyorsuló szakaszok a korlátozásig
if (d < gyorsulut(0,v)+gyorsulut(v,w)) {
double x = Math.sqrt(a*(d-w*w/(2*a))+w*w);
s-=gyorsulut(0,w)+2*gyorsulut(w,x);
t+=gyorsulido(0,w)+2*gyorsulido(w,x);
}
else {
s-=gyorsulut(0,v)+gyorsulut(w,v);
t+=gyorsulido(0,v)+gyorsulido(w,v);
}
//gyorsuló szakaszok a korlátozástól
if (gyorsulut(v,w) > l-d) {
double y = Math.sqrt(2*a*(l-d)+w*w);
s-= gyorsulut(w,y);
t+=gyorsulido(w,y);
}
else {
s-=gyorsulut(w,v);
t+=gyorsulido(w,v);
}
}
t+=s/v; //nem gyorsuló szakaszok ideje
System.out.println(t);
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
import java.util.*;
import java.math.*;
public class D5 {
static int a, v, l, d;
static double w;
static double afterMark( int s, double w) {
if (2 * s * a > v * v - w * w) { // ���� ��������� v. ����� ��
return (v - w) * 1.0 / a + (s - (v * v - w * w) * 1.0 / (2 * a)) / v;
} else { // ���������
double megav = Math.sqrt((2 * a * s + w * w) * 1.0);
return (megav - w) / a;
}
}
public static void main(String args[]) throws IOException {
boolean online = System.getProperty("ONLINE_JUDGE") != null;
Scanner in = online ? new Scanner(System.in) : new Scanner(new FileReader("input.txt"));
PrintWriter out = online ? new PrintWriter(System.out) : new PrintWriter(new FileWriter("output.txt"));
a = in.nextInt();
v = in.nextInt();
l = in.nextInt();
d = in.nextInt();
w = (double) in.nextInt();
double t,t1,t2;
if (v > w) { // ����� ��������� ������, ����� ����� ���
// ������� ������ �� �����
if (2 * d * a > 2 * v * v - w * w) { // ���� ��������� v. ����� ��
t1 = (2 * v - w) * 1.0 / a + (d - (2 * v * v - w * w) * 1.0 / (2 * a)) / v;
} else if (2 * d * a > w * w) { // ���� �� ���������, �� ���� � ���� - ���������
double topv = Math.sqrt(d * a + w * w * 1.0 / 2);
t1 = (2 * topv - w) * 1.0 / a;
} else { // ���� ����������� �� ������ ����� - �����, ���������
t1 = Math.sqrt(2 * d * 1.0 / a);
w = Math.sqrt(2 * a * d * 1.0);
}
// ������� ������ ����� �����
t2 = afterMark(l - d, w);
t = t1 + t2;
} else {
t = afterMark(l, 0.0);
}
out.println(t);
out.flush();
return;
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.*;
import static java.lang.Math.*;
public final class FollowTrafficRules {
private static double[] acce(double i, double a, double v) {
double[] r = new double[2];
r[0] = (v - i)/a;
r[1] = 1d/2d * a * pow(r[0], 2) + i * r[0];
return r;
}
private static double solve(double i, double a, double l) {
double e = sqrt(pow(i, 2) + 2d * a * l);
e = a > 0 ? e : -1d * e;
return (e - i)/a;
}
private static double time(double i, double a, double v, double l) {
double[] r = acce(i, a, v);
if (r[1] >= l) return solve(i, a, l);
return r[0] + (l - r[1])/v;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a = sc.nextDouble();
double v = sc.nextDouble();
double l = sc.nextDouble();
double d = sc.nextDouble();
double w = sc.nextDouble();
double t = 0d;
double[] r = acce(0, a, w);
if (v <= w || r[1] >= d) t = time(0, a, v, l);
else {
t += r[0];
t += 2d * time(w, a, v, (d - r[1])/2d);
t += time(w, a, v, l - d);
}
System.out.println(t);
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.*;
public class Rules {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
double maxSpeed = in.nextInt();
double len = in.nextInt();
double delayDist = in.nextInt();
double delaySpeed = in.nextInt();
double timeToDelaySpeed = delaySpeed/a;
double timeToDelay = travelS(a, 0.0, maxSpeed, delayDist);
//System.out.printf("timeToDelaySpeed=%.5f, timeToDelay=%.5f\n", timeToDelaySpeed, timeToDelay);
if (timeToDelay < timeToDelaySpeed) { // we won't reach delaySpeed before delay marker
// 2 cases: we don't reach max by time we reach end
timeToDelay = travelS(a, 0.0, maxSpeed, len);
double timeToMax = maxSpeed/a;
if (timeToDelay < timeToMax) {
System.out.printf("%.9f\n", timeToDelay);
return;
}
// we do reach max, then travel at max
double[] parts = travelA(a, 0.0, maxSpeed);
double remainingDist = len - parts[1];
double time = parts[0] + remainingDist / maxSpeed;
System.out.printf("%.9f\n", time);
return;
}
if (delaySpeed > maxSpeed) {
double time = travelS(a, 0.0, maxSpeed, len);
System.out.printf("%.9f\n", time);
return;
}
// binary search to find best velocity to stop acceleration in beginning
double lowV = delaySpeed;
double highV = maxSpeed;
int loopCount = 1000;
double[] initial = null;
double[] secondary = null;
while (loopCount-->0) {
double guessV = (lowV+highV)/2.0;
initial = travelA(a, 0.0, guessV);
secondary = travelA(a, guessV, Math.min(delaySpeed, maxSpeed));
if (initial[1] + secondary[1] < delayDist) { // okay, we can go faster
lowV = guessV;
} else {
highV = guessV;
}
}
double totalTime = 0.0;
double finalSpeed = 0.0;
initial = travelA(a, 0.0, lowV);
secondary = travelA(a, lowV, delaySpeed);
totalTime = initial[0] + secondary[0];
double totalDist = initial[1] + secondary[1];
totalTime += (delayDist-totalDist)/maxSpeed;
// now we have delayDist to go, and we are at delaySpeed
totalTime += travelS(a, delaySpeed, maxSpeed, len-delayDist);
System.out.printf("%.9f\n", totalTime);
}
// [0] = time in h, [1] = dist travelled, in km
// input units are in km/h^2, km/h, km/h
public static double[] travelA(int a, double startSpeed, double endSpeed) {
if (startSpeed > endSpeed)
a = -a;
double time = (endSpeed - startSpeed) / a;
double dist = 0.5*a*time*time + startSpeed*time;
return new double[] {time, dist};
}
// returns time it takes to travel dist, with given inputs
public static double travelS(int a, double startSpeed, double maxSpeed, double dist) {
double timeToMax = (maxSpeed - startSpeed) / a;
double targetTime = (-startSpeed + Math.sqrt(startSpeed*startSpeed + 2*a*dist)) / a;
if (targetTime < timeToMax)
return targetTime;
double partialDist = 0.5*timeToMax*timeToMax*a + startSpeed*timeToMax;
double remainingDist = dist - partialDist;
targetTime = remainingDist / maxSpeed;
return targetTime + timeToMax;
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
import java.text.*;
import java.math.*;
import java.util.*;
public class Main {
private BufferedReader in;
private BufferedWriter out;
double time(double a, double l, double v0, double v) {
double t = (v - v0) / a;
double s = a * t * t / 2 + v0 * t;
if (s <= l) {
return t + (l - s) / v;
}
double B = v0, C = -l;
double D = Math.sqrt(B * B - 2 * a * C);
return (-B + D) / a;
}
// )(()()))(())))
public void solve() throws Exception {
StreamTokenizer st = new StreamTokenizer(in);
st.nextToken();
double a = st.nval;
st.nextToken();
double v = st.nval;
st.nextToken();
double l = st.nval;
st.nextToken();
double d = st.nval;
st.nextToken();
double w = st.nval;
double ttt = Math.sqrt(2 * d / a);
double ans = 0.0;
if (w > v || ttt * a < w) {
ans = time(a, l, 0, v);
} else {
double B = 2 * w / a, C = -w * w / (a * a) - 4 * d / a;
double D = Math.sqrt(B * B - 4 * C);
ans = (-B + D) / 2;
if ((a * ans + w) / 2.0 > v) {
double t1 = v / a;
double t2 = (v - w) / a;
double s = (a * t1 * t1 / 2.0) + (v * t2 - a * t2 * t2 / 2.0);
ans = t1 + t2 + (d - s) / v;
}
ans += time(a, l - d, w, v);
}
DecimalFormat df = new DecimalFormat("0.000000000");
out.write(df.format(ans) + "\n");
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new BufferedWriter(new OutputStreamWriter(System.out));
solve();
out.flush();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public static void main(String[] args) {
try {
Locale.setDefault(Locale.US);
} catch (Exception e) {
}
new Main().run();
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
FastScanner in;
PrintWriter out;
public void solve() throws IOException {
double a = in.nextInt();
double v = in.nextInt();
double l = in.nextInt();
double d = in.nextInt();
double w = in.nextInt();
if (w * w / (a * 2) > d || v < w) {
if (v * v / (a * 2) > l) {
out.println(Math.sqrt(l * 2 / a));
}
else {
double t = v / a;
double s = l - t * v / 2;
t = t + s / v;
out.println(t);
}
return;
}
double t = solveD(a, v, w, d);
if ((v + w) * (v - w) / (a * 2) > l - d) {
double dis = w * w + a * (l - d) * 2;
double t1 = (Math.sqrt(dis) - w) / a;
System.out.println(t + t1);
}
else {
double t1 = (v - w) / a;
double s = l - d - (v + w) * t1 / 2;
double t2 = s / v;
System.out.println(t + t1 + t2);
}
}
public double solveD(double a, double vMax, double wBound, double s) {
double v = Math.sqrt(a * s + wBound * wBound / 2);
if (v > vMax) {
v = vMax;
}
double t1 = v / a;
double t2 = (v - wBound) / a;
double s1 = v * t1 / 2;
double s2 = (v + wBound) * t2 / 2;
double sr = s - s1 - s2;
double tr = sr / v;
return t1 + t2 + tr;
}
public void run() {
try {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
solve();
out.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
public static void main(String[] arg) {
new Main().run();
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class D {
public static void main(String[] args) throws IOException {
new D().solve();
}
static final double EPS = 1e-10;
Parser parser;
enum Result {
UNDER, OVER
}
private void solve() throws IOException {
this.parser = new Parser(new BufferedReader(new InputStreamReader(System.in)));
double a = parser.nextInt();
double vmax = parser.nextInt();
double l = parser.nextInt();
double d = parser.nextInt();
double w = parser.nextInt();
double low = 0;
double high = 20000;
while (Math.abs(high - low) > 1e-10) {
double accelerateTime = (low + high) / 2;
Result res = check(accelerateTime, a, vmax, d, w).result;
if (res == Result.UNDER) {
low = accelerateTime;
} else {
high = accelerateTime;
}
}
IP ip = check(high, a, vmax, d, w);
TV tv = tv(ip.v, l - d, a, vmax);
PrintWriter pw = new PrintWriter(System.out);
pw.printf("%.5f\n", ip.time + tv.time);
pw.close();
}
private IP check(double accelerateTime, double a, double vmax, double d, double w) {
DV dv = dv(0, a, accelerateTime, vmax);
if (dv.d > d) {
return new IP(accelerateTime, dv.v, Result.OVER);
}
Double slowTime = time2MakeDist(-a, dv.v, d - dv.d);
if (slowTime == null) {
return new IP(0, 0, Result.UNDER);
}
double vDown = dv.v - a * slowTime;
if (vDown < w) {
return new IP(0, 0, Result.UNDER);
} else {
return new IP(accelerateTime + slowTime, vDown, Result.OVER);
}
}
static class IP {
final double time;
final double v;
final Result result;
IP(double time, double v, Result result) {
this.time = time;
this.v = v;
this.result = result;
}
}
static class DV {
final double d;
final double v;
DV(double d, double v) {
this.d = d;
this.v = v;
}
}
static class TV {
final double time;
final double v;
TV(double time, double v) {
this.time = time;
this.v = v;
}
}
static Double time2MakeDist(double a, double v0, double dist) {
return quadric(a / 2, v0, -dist);
}
static TV tv(double v0, double d, double a, double vmax) {
double acTime = (vmax - v0) / a;
double unboundedTime = time2MakeDist(a, v0, d);
if (unboundedTime > acTime) {
double ad = dist(v0, a, acTime);
return new TV(acTime + (d - ad) / vmax, vmax);
} else {
return new TV(unboundedTime, v0 + a * unboundedTime);
}
}
static DV dv(double v0, double a, double time, double vmax) {
double time2maxV = (vmax - v0) / a;
if (time2maxV < time) {
return new DV(dist(v0, a, time2maxV) + dist(vmax, 0, time - time2maxV), vmax);
} else {
return new DV(dist(v0, a, time), v0 + a * time);
}
}
static double dist(double v0, double a, double time) {
return v0 * time + a * time * time / 2;
}
static Double quadric(final double a, final double b, final double c) {
double d = b * b - 4 * a * c;
if (d < -EPS) {
return null;
}
d = Math.abs(d);
double x1 = (-b + Math.sqrt(d)) / (2 * a);
double x2 = (-b - Math.sqrt(d)) / (2 * a);
double r = Integer.MAX_VALUE;
if (x1 > -EPS) {
r = x1;
}
if (x2 > -EPS) {
r = Math.min(r, x2);
}
if (r == Integer.MAX_VALUE) {
throw new RuntimeException("BOTVA");
}
return r;
}
static class Parser {
final BufferedReader br;
StringTokenizer st = new StringTokenizer("");
public Parser(BufferedReader bufferedReader) {
this.br = bufferedReader;
}
String nextToken() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author madis
*/
public class Rules {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double a = in.nextInt();
double v = in.nextInt();
double l = in.nextInt();
double d = in.nextInt();
double w = in.nextInt();
if (v <= w) {
double t = v / a;
if (0.5 * t * t * a > l) {
t = Math.sqrt(2 * l / a);
} else {
t += (l - 0.5 * t * t * a) / v;
}
System.out.printf("%.5f", t);
} else {
double total = 0.0;
double t = v / a;
double t2 = (v - w) / a;
double tempt = Math.sqrt(2.0 * d / a);
if (tempt * a <= w) {
total += tempt;
w = tempt*a;
} else if (0.5 * t * t * a +v*t2 - 0.5 * t2 * t2 * a > d) {
double as = 2.0*a;
double bs = 4.0*w;
double cs = ((w * w) / (a) - 2.0 * d );
double delta = bs * bs - 4.0 * as * cs;
double root = (-bs + Math.sqrt(delta)) / (2.0 * as);
if (root < 0.0) {
root = (-bs - Math.sqrt(delta)) / (2.0 * as);
}
total += (2.0 * root + w / a);
} else {
total += t + t2;
double smd = (d - 0.5 * t * t * a - v*t2 + 0.5 * t2 * t2 * a) / v;
total += smd;
}
double t3 = (v - w) / a;
if (w * t3 + 0.5 * t3 * t3 * a > l - d) {
double as = 0.5 * a;
double bs = w;
double cs = d - l;
double delta = bs * bs - 4.0 * as * cs;
double root = (-bs + Math.sqrt(delta)) / (2.0 * as);
if (root < 0.0) {
root = (-bs - Math.sqrt(delta)) / (2.0 * as);
}
total += root;
} else {
total += t3;
double t4 = (l - (w * t3 + 0.5 * t3 * t3 * a) - d) / v;
total += t4;
}
System.out.printf("%.5f", total);
}
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
import java.util.*;
import java.math.*;
public class Solution implements Runnable {
private BufferedReader in;
private PrintWriter out;
private StringTokenizer st;
private Random rnd;
double Vend;
private double calcFirstSegment(double a, double Vmax, double Vend, double l) {
double Vl = 0, Vr = Vmax;
for(int it = 0; it < 256; it++) {
double Vm = (Vl + Vr) / 2.0;
double tFirst = Vm / a;
double tSecond = 0;
if(Vend < Vm) tSecond = (Vm - Vend) / a;
double firstPart = a * tFirst * tFirst / 2.0;
double secondPart = Vm * tSecond - a * tSecond * tSecond / 2.0;
double res = firstPart + secondPart;
if(res < l) Vl = Vm;
else Vr = Vm;
}
this.Vend = Math.min(Vl, Vend);
double res = 0.0;
{
double Vm = Vl;
double tFirst = Vm / a;
double tSecond = 0;
if(Vend < Vm) tSecond = (Vm - Vend) / a;
//out.println(tSecond);
double firstPart = a * tFirst * tFirst / 2.0;
double secondPart = Vm * tSecond - a * tSecond * tSecond / 2.0;
double remain = l - firstPart - secondPart;
res = tFirst + tSecond + (remain / Vm);
}
return res;
}
private double calcSecondPart(double a, double Vmax, double Vstart, double l) {
double Vl = Vstart, Vr = Vmax;
//out.println(Vstart);
for(int it = 0; it < 256; it++) {
double Vm = (Vl + Vr) / 2.0;
double t = (Vm - Vstart) / a;
double s = Vstart * t + a * t * t / 2.0;
if(s < l) Vl = Vm;
else Vr = Vm;
}
double res = 0.0;
{
double Vm = (Vl + Vr) / 2.0;
double t = (Vm - Vstart) / a;
double s = Vstart * t + a * t * t / 2.0;
double remain = l - s;
res = t + (remain / Vmax);
}
return res;
}
public void solve() throws IOException {
double a = nextDouble(), v = nextDouble(), l = nextDouble(), d = nextDouble(), w = nextDouble();
double res = calcFirstSegment(a, v, w, d);
res += calcSecondPart(a, v, Vend, l - d);
out.println(res);
}
public static void main(String[] args) {
new Solution().run();
}
public void run() {
try {
//in = new BufferedReader(new FileReader("input.txt"));
//out = new PrintWriter(new FileWriter("output.txt"));
in = new BufferedReader(new InputStreamReader((System.in)));
out = new PrintWriter(System.out);
st = null;
rnd = new Random();
solve();
out.close();
} catch(IOException e) {
e.printStackTrace();
}
}
private String nextToken() throws IOException, NullPointerException {
while(st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
private int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
private long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
private double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Berland implements Runnable {
private void solve() throws IOException {
double a = nextInt();
double v = nextInt();
double l = nextInt();
double d = nextInt();
double w = nextInt();
double res;
if (v <= w) {
res = simpleCase(a, v, l, 0);
} else {
double vMax = Math.sqrt(2 * d * a);
if (vMax <= w) {
res = simpleCase(a, v, l, 0);
} else {
double tFullSpeed = v / a;
double tSlowdown = (v - w) / a;
if (a * tFullSpeed * tFullSpeed / 2 + v * tSlowdown - a * tSlowdown * tSlowdown / 2 <= d) {
res = tFullSpeed + tSlowdown + (d - (a * tFullSpeed * tFullSpeed / 2 + v * tSlowdown - a * tSlowdown * tSlowdown / 2)) / v + simpleCase(a, v, l - d, w);
} else {
double min = w;
double max = v;
for (int i = 0; i < 1000; ++i) {
double cur = (min + max) / 2;
double cFullSpeed = cur / a;
double cSlowdown = (cur - w) / a;
if (a * cFullSpeed * cFullSpeed / 2 + cur * cSlowdown - a * cSlowdown * cSlowdown / 2 <= d)
min = cur;
else
max = cur;
}
res = min / a + (min - w) / a + simpleCase(a, v, l - d, w);
}
}
}
writer.printf("%.20f\n", res);
}
private double simpleCase(double a, double v, double l, double v0) {
double tFullSpeed = (v - v0) / a;
if (v0 * tFullSpeed + a * tFullSpeed * tFullSpeed / 2 <= l) {
return tFullSpeed + (l - (v0 * tFullSpeed + a * tFullSpeed * tFullSpeed / 2)) / v;
} else {
double min = 0;
double max = tFullSpeed;
for (int i = 0; i < 1000; ++i) {
double cur = (min + max) / 2;
if (v0 * cur + a * cur * cur / 2 <= l)
min = cur;
else
max = cur;
}
return min;
}
}
public static void main(String[] args) {
new Berland().run();
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run() {
try {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
writer = new PrintWriter(System.out);
solve();
reader.close();
writer.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.PrintWriter;
import java.util.Scanner;
/**
* @author Egor Kulikov ([email protected])
* Created on 14.03.2010
*/
public class Rules implements Runnable {
private Scanner in = new Scanner(System.in);
private PrintWriter out = new PrintWriter(System.out);
private double a, v, l, d, w;
private double ans;
public static void main(String[] args) {
new Thread(new Rules()).start();
}
public void run() {
read();
solve();
write();
out.close();
}
private void read() {
a = in.nextInt();
v = in.nextInt();
l = in.nextInt();
d = in.nextInt();
w = in.nextInt();
}
private double remaining(double v0, double dst) {
double t = (v - v0) / a;
double d = a * t * t / 2 + t * v0;
if (d > dst)
return (Math.sqrt(v0 * v0 + 2 * a * dst) - v0) / a;
return t + (dst - d) / v;
}
private void solve() {
if (w * w >= 2 * a * d || w >= v) {
ans = remaining(0, l);
return;
}
{
double t1 = v / a;
double t2 = (v - w) / a;
double dd = a * t1 * t1 / 2 + a * t2 * t2 / 2 + w * t2;
if (dd < d) {
ans = t1 + t2 + (d - dd) / v + remaining(w, l - d);
return;
}
}
double t1 = w / a;
double rd = d - t1 * t1 * a / 2;
double t2 = (Math.sqrt(w * w + a * rd) - w) / a;
ans = t1 + 2 * t2 + remaining(w, l - d);
}
private void write() {
out.printf("%.7f\n", ans);
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
import java.util.*;
public class D {
static Scanner in = new Scanner(new BufferedInputStream(System.in));
static PrintWriter out = new PrintWriter(System.out);
static double getTime(double v, double a, double l, double r) {
return (-v + Math.sqrt(v * v - 2 * a * (l - r))) / a;
}
static double getVelocity(double v, double t, double l, double r) {
return t == 0 ? v : (2 * (r - l)) / t - v;
}
public static void main(String[] args) throws IOException {
double a = in.nextDouble(), v = in.nextDouble(), l = in.nextDouble(),
d = in.nextDouble(), w = Math.min(v, in.nextDouble());
double x = v * v / (2 * a), y = d - (v * v - w * w) / (2 * a),
z = d + (v * v - w * w) / (2 * a);
//out.println(x + " " + y + " " + z);
double L, R, T = 0, V = 0, t;
//OX
L = 0;
R = x;
if (x > y && x < z) {
R = (x + y) / 2;
} else if (x > l) {
R = l;
}
t = getTime(V, a, L, R);
V = getVelocity(V, t, L, R);
//out.println("l: " + L + ", r: " + R + ", t: " + t + ", v: " + V);
T += t;
//XY
if (x < y) {
T += (y - x) / v;
}
//out.println("t: " + (T - t));
//YD
L = y;
R = d;
if (x > y && x < z) {
L = (x + y) / 2;
} else if (x >= z) {
L = R;
}
t = getTime(V, -a, L, R);
V = getVelocity(V, t, L, R);
T += t;
//out.println("l: " + L + ", r: " + R + ", t: " + t + ", v: " + V);
//DZ
L = d;
R = z;
if (x >= z) {
R = L;
} else if (z > l) {
R = l;
}
t = getTime(V, a, L, R);
V = getVelocity(V, t, L, R);
T += t;
//out.println("l: " + L + ", r: " + R + ", t: " + t + ", v: " + V);
//ZL
L = z;
R = l;
if (x > z) {
L = x;
}
if (L < R) {
T += (R - L) / v;
}
out.format(Locale.US, "%.12f%n", T);
out.close();
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.math.BigInteger;
public class Main {
final int INF = 1000000000;
final int MAXN = 100100;
Scanner input = new Scanner(System.in);
BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
new Main().run();
}
double a, v;
double l, d, w;
void run() throws IOException {
a = input.nextDouble();
v = input.nextDouble();
l = input.nextDouble();
d = input.nextDouble();
w = input.nextDouble();
if (v <= w) {
out.println(timeTravel(l, 0));
} else {
double tw = w / a;
double dw = dist(tw, 0);
if (dw >= d) {
out.println(timeTravel(l, 0));
} else {
double tSym = timeTravel((d - dw) / 2, w);
out.println(tw + 2 * tSym + timeTravel(l - d, w));
}
}
out.close();
}
double dist(double time, double speed) {
return speed * time + a * time * time / 2;
}
double timeTravel(double distance, double speed) {
double delta = speed * speed + 2 * a * distance;
double tAll = (Math.sqrt(delta) - speed) / a;
double tMax = (v - speed) / a;
if (tMax >= tAll) {
return tAll;
} else {
return tMax + (distance - dist(tMax, speed)) / v;
}
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.Scanner;
public class Task5d {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a = sc.nextDouble();
double v = sc.nextDouble();
double l = sc.nextDouble();
double d = sc.nextDouble();
double w = sc.nextDouble();
double t = 0;
if (w >= v) {
double t1 = v / a;
double s1 = a * t1 * t1 / 2;
if (s1 > l) {
t = Math.sqrt(2 * l / a);
} else {
t = t1 + (l - s1) / v;
}
} else {
double t2 = Math.sqrt(2 * d / a);
if (a * t2 <= w) {
double t1 = v / a;
double s1 = a * t1 * t1 / 2;
if (s1 > l) {
t = Math.sqrt(2 * l / a);
} else {
t = t1 + (l - s1) / v;
}
} else {
double tup = v / a;
double tdown = (v - w) / a;
double sup = a * tup * tup / 2;
double sdown = v * tdown - a * tdown * tdown / 2;
if (sup + sdown <= d) {
double tmax = (d - sup - sdown) / v;
t = tup + tmax + tdown;
} else {
double tw = w / a;
double sw = a * tw * tw / 2;
double sl = (d - sw) / 2;
double dis = w * w + 2 * a * sl;
double tu1 = (- w - Math.sqrt(dis)) / a;
if (tu1 < 0) {
tu1 = (- w + Math.sqrt(dis)) / a;
}
t = tw + 2 * tu1;
}
double sreup = w * tdown + a * tdown * tdown / 2;
if (sreup <= l - d) {
t += tdown;
t += (l - d - sreup) / v;
} else {
double dis = w * w - 2 * a * (d - l);
double tu1 = (- w - Math.sqrt(dis)) / a;
if (tu1 < 0) {
tu1 = (- w + Math.sqrt(dis)) / a;
}
t += tu1;
}
}
}
System.out.println(t);
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class D5 implements Runnable {
final double eps = 1e-9;
private void Solution() throws IOException {
double a = nextDouble(), v = nextDouble();
double l = nextDouble(), d = nextDouble(), w = nextDouble();
double t = 0;
if (w + eps > v) {
double s = v * v / (2 * a);
if (s + eps > l)
t = Math.sqrt(2 * l / a);
else {
double ta = v / a;
double sa = a * ta * ta / 2;
t = ta + (l - sa) / v;
}
} else {
double sv = v * v / (2 * a);
double sw = w * w / (2 * a);
if (sw + eps > d) {
if (sv + eps > l)
t = Math.sqrt(2 * l / a);
else {
double ta = v / a;
double sa = a * ta * ta / 2;
t = ta + (l - sa) / v;
}
} else {
double sd = (w * w - v * v) / (-2 * a);
if (sv + sd < eps + d)
t = v / a + (d - sv - sd) / v + (v - w) / a;
else {
double f = Math.sqrt(d * a + w * w / 2);
t = f / a + (f - w) / a;
}
if (sd + eps > l - d) {
double lv = Math.sqrt((l - d) * 2 * a + w * w);
t += (lv - w) / a;
} else {
t += (v - w) / a + (l - d - sd) / v;
}
}
}
out.printf("%.12f", t);
}
public static void main(String[] args) {
new D5().run();
}
BufferedReader in;
PrintWriter out;
StringTokenizer tokenizer;
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
Solution();
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
void print(Object... obj) {
for (int i = 0; i < obj.length; i++) {
if (i != 0)
out.print(" ");
out.print(obj[i]);
}
}
void println(Object... obj) {
print(obj);
print("\n");
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(next());
}
double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(next());
}
String nextLine() throws IOException {
return in.readLine();
}
String next() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(nextLine());
return tokenizer.nextToken();
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
public class n5D
{
public static void main(String[] args)
{
double a = 0, v = 0, l = 0, d = 0, w = 0;
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str = br.readLine().split(" ");
a = Double.parseDouble(str[0]);
v = Double.parseDouble(str[1]);
str = br.readLine().split(" ");
l = Double.parseDouble(str[0]);
d = Double.parseDouble(str[1]);
w = Double.parseDouble(str[2]);
}
catch(Exception e)
{
System.out.println(e);
}
double t1, t2, t3, t4, t5, t, D = 0;
if (w > v) w = v;
t2 = d / v - v / a + w * w / 2 / a / v;
if (t2 >= 0)
{
t1 = v / a;
t3 = t1 - w / a;
}
else
{
if (Math.sqrt(2 * d / a) > (w / a))
{
t1 = Math.sqrt((2 * a * d + w * w) / (a * a * 2));
t3 = t1 - w / a;
}
else
{
t1 = Math.sqrt(2 * d / a);
t3 = 0;
}
t2 = 0;
}
t5 = (l - d - v * v / 2 / a + a * (t1 - t3) * (t1 - t3) / 2) / v;
if (t5 >= 0) t4 = v / a - (t1 - t3);
else
{
t5 = 0;
t4 = -t1 + t3 + Math.sqrt((t1 - t3) * (t1 - t3) + 2 * (l - d) / a);
}
t = t1 + t2 + t3 + t4 + t5;
System.out.println(t);
//System.out.println(t1 + " " + t2 + " " + t3 + " " + t4 + " " + t5);
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class D5 {
static StringTokenizer st;
static BufferedReader in;
public static void main(String[] args) throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
double a = nextInt();
double v = nextInt();
double L = nextInt();
double d = nextInt();
double w = nextInt();
double ans = 0;
if (w >= v)
ans = go(0, a, L, v);
else {
ans = go(Math.min(w, Math.sqrt(2*a*d)), a, L-d, v);
if (2*a*d < w*w)
ans += Math.sqrt(2*d/a);
else {
if (d-v*v/(2*a) >= (v*v-w*w)/(2*a))
ans += v/a+(v-w)/a+(d-v*v/(2*a)-(v*v-w*w)/(2*a))/v;
else {
double x = Math.sqrt((w*w+2*a*d)/2);
ans += x/a+(x-w)/a;
}
}
}
System.out.println(ans);
pw.close();
}
private static double go(double v0, double a, double s, double vmax) {
double t = (vmax-v0) / a;
if (v0*t+a*t*t/2 < s)
return t+(s-v0*t-a*t*t/2) / vmax;
else {
double D = v0*v0+2*a*s;
return (-v0+Math.sqrt(D))/a;
}
}
private static int nextInt() throws IOException{
return Integer.parseInt(next());
}
private static long nextLong() throws IOException{
return Long.parseLong(next());
}
private static double nextDouble() throws IOException{
return Double.parseDouble(next());
}
private static String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.*;
public class Rules {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
double maxSpeed = in.nextInt();
double len = in.nextInt();
double delayDist = in.nextInt();
double delaySpeed = in.nextInt();
// two cases: I reach the delayPoint at a speed higher than the delaySpeed, or I don't.
double timeToDelayAtMax = travelS(a, 0.0, maxSpeed, delayDist);
double timeToDelayAtDelay = travelS(a, 0.0, delaySpeed, delayDist);
if (Math.abs(timeToDelayAtMax-timeToDelayAtDelay) < 0.00001) {
// I can reach the delayPoint without being delayed
double time = travelS(a, 0.0, maxSpeed, len);
System.out.printf("%.9f\n", time);
return;
}
// binary search to find best velocity to stop acceleration in beginning
double lowV = delaySpeed;
double highV = maxSpeed;
int loopCount = 1000;
double[] initial = null;
double[] secondary = null;
while (loopCount-->0) {
double guessV = (lowV+highV)/2.0;
initial = travelA(a, 0.0, guessV);
secondary = travelA(a, guessV, Math.min(delaySpeed, maxSpeed));
if (initial[1] + secondary[1] < delayDist) { // okay, we can go faster
lowV = guessV;
} else {
highV = guessV;
}
}
double totalTime = 0.0;
double finalSpeed = 0.0;
initial = travelA(a, 0.0, lowV);
secondary = travelA(a, lowV, delaySpeed);
totalTime = initial[0] + secondary[0];
double totalDist = initial[1] + secondary[1];
totalTime += (delayDist-totalDist)/maxSpeed;
// now we have delayDist to go, and we are at delaySpeed
totalTime += travelS(a, delaySpeed, maxSpeed, len-delayDist);
System.out.printf("%.9f\n", totalTime);
}
// [0] = time in h, [1] = dist travelled, in km
// input units are in km/h^2, km/h, km/h
public static double[] travelA(int a, double startSpeed, double endSpeed) {
if (startSpeed > endSpeed)
a = -a;
double time = (endSpeed - startSpeed) / a;
double dist = 0.5*a*time*time + startSpeed*time;
return new double[] {time, dist};
}
// returns time it takes to travel dist, with given inputs
public static double travelS(int a, double startSpeed, double maxSpeed, double dist) {
double timeToMax = (maxSpeed - startSpeed) / a;
double targetTime = (-startSpeed + Math.sqrt(startSpeed*startSpeed + 2*a*dist)) / a;
if (targetTime < timeToMax)
return targetTime;
double partialDist = 0.5*timeToMax*timeToMax*a + startSpeed*timeToMax;
double remainingDist = dist - partialDist;
targetTime = remainingDist / maxSpeed;
return targetTime + timeToMax;
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
import java.util.*;
public class D {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
double f(int dist, double initSp, int a, int maxSp) {
double distToReachMaxSpeed = 0.5 * (maxSp * maxSp - initSp * initSp)
/ a;
if (dist > distToReachMaxSpeed)
return 1d * (maxSp - initSp) / a + (dist - distToReachMaxSpeed)
/ maxSp;
return (Math.sqrt(initSp * initSp + 2 * a * dist) - initSp) / a;
}
void solve() throws IOException {
int a = nextInt();
int maxSp = nextInt();
int len = nextInt();
int signX = nextInt();
int signSp = nextInt();
if (maxSp <= signSp) {
out.printf("%.9f\n", f(len, 0, a, maxSp));
return;
}
double distToReachSignSp = 0.5 * signSp * signSp / a;
if (distToReachSignSp >= signX) {
out.printf("%.9f\n", f(len, 0, a, maxSp));
return;
}
double distToReachMaxThenSign = 0.5
* (maxSp * maxSp + maxSp * maxSp - signSp * signSp) / a;
if (distToReachMaxThenSign <= signX) {
double t = 1d * (2 * maxSp - signSp) / a
+ (signX - distToReachMaxThenSign) / maxSp
+ f(len - signX, signSp, a, maxSp);
out.printf("%.9f\n", t);
return;
}
double xSp = Math.sqrt(a * signX + signSp * signSp * 0.5);
double xTime = (2 * xSp - signSp) / a;
out.printf("%.9f\n", xTime + f(len - signX, signSp, a, maxSp));
}
void inp() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new D().inp();
}
String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.nextToken();
}
String nextString() {
try {
return br.readLine();
} catch (IOException e) {
eof = true;
return null;
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.*;
import java.io.*;
public class D0005 {
public static void main(String args[]) throws Exception {
new D0005();
}
D0005() throws Exception {
PandaScanner sc = null;
PrintWriter out = null;
try {
sc = new PandaScanner(System.in);
out = new PrintWriter(System.out);
} catch (Exception ignored) {
}
a = sc.nextInt();
max = sc.nextInt();
double length = sc.nextInt();
double dist = sc.nextInt();
double limit = sc.nextInt();
if (max <= limit) {
out.println(travelTime(length, 0));
}
else {
double tLimit = limit / a;
double dLimit = distance(0, tLimit);
if (dLimit >= dist) {
out.println(travelTime(length, 0));
}
else {
double res = tLimit + 2 * (travelTime(0.5 * (dist - dLimit), limit)) +
travelTime(length - dist, limit);
out.println(res);
}
}
out.close();
System.exit(0);
}
double a, max;
double distance(double v, double t) {
return v * t + 0.5 * a * t * t;
}
double travelTime(double d, double v) {
double tAll = (-v + Math.sqrt(v * v + 2 * a * d)) / a;
double tMax = (max - v) / a;
if (tAll <= tMax) {
return tAll;
}
else {
return tMax + (d - distance(v, tMax)) / max;
}
}
//The PandaScanner class, for Panda fast scanning!
public class PandaScanner {
BufferedReader br;
StringTokenizer st;
InputStream in;
PandaScanner(InputStream in) throws Exception {
br = new BufferedReader(new InputStreamReader(this.in = in));
}
public String next() throws Exception {
if (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine().trim());
return next();
}
return st.nextToken();
}
public boolean hasNext() throws Exception {
return (st != null && st.hasMoreTokens()) || in.available() > 0;
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.*;
import java.io.*;
public class Traffic extends Template{
public double search1(int a, int w, int d){
double s = 0;
double l = 2*w+2*a*d;
int repeat = 100;
while( repeat-- > 0 ){
double x = (s+l)/2;
if( a*a*x*x + 2*a*w*x - w*w - 4*a*d > 0 ){
l = x;
} else {
s = x;
}
}
return l;
}
public double search2(int a, double lim, int k){
double s = 0;
double l = lim + 2*a*k;
int repeat = 100;
while( repeat-- > 0 ){
double x = (s+l)/2;
if( a*x*x + 2*lim*x - 2*k > 0 ){
l = x;
} else {
s = x;
}
}
return l;
}
public void solve() throws IOException {
int a = nextInt();
int v = nextInt();
int l = nextInt();
int d = nextInt();
int w = nextInt();
if( w > v ){
w = v;
}
double time_max = Math.sqrt((double)2*d/a);
double time_d = search1(a,w,d);
// writer.println(time_max*a < w); writer.println(v <= (w+a*time_d)/2); writer.println(w < v);
double t1 = (time_max*a < w) ? time_max : (v >= (w+a*time_d)/2) ? time_d : (w < v) ? (double)(2*v*v-2*v*w+2*a*d+w*w)/(2*a*v) : (double)v/a + (double)(d-(double)v*v/(2*a))/v;
double lim = (time_max*a < w) ? time_max*a : w;
double t3 = Math.min((double)(v-lim)/a, search2(a, lim, l-d));
// double t = (Math.sqrt(limit*limit+2*a*(l-d))-limit)/a;
double dist2 = (l-d) - t3*t3*a/2 - t3*lim;
double t4 = dist2/v;
// writer.println("t1 = " + t1);
// writer.println("dist1 = " + dist1);
// writer.println("t3 = " + t3);
// writer.println("dist2 = " + dist2);
// writer.println("t4 = " + t4);
writer.println((t1+t3+t4));
}
public static void main(String[] args){
new Traffic().run();
}
}
abstract class Template implements Runnable{
public abstract void solve() throws IOException;
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run(){
try{
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
writer = new PrintWriter(System.out);
solve();
reader.close();
writer.close();
} catch(Exception e){
e.printStackTrace();
System.exit(1);
}
}
public int nextInt() throws IOException{
return Integer.parseInt(nextToken());
}
public String nextToken() throws IOException{
while( tokenizer == null || !tokenizer.hasMoreTokens() ){
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.StringTokenizer;
public class Main implements Runnable {
static Throwable sError;
public static void main(String[] args) throws Throwable {
Thread t = new Thread(new Main());
t.start();
t.join();
if (sError != null)
throw sError;
}
PrintWriter pw;
BufferedReader in;
StringTokenizer st;
void initStreams() throws FileNotFoundException,
UnsupportedEncodingException {
pw = new PrintWriter(System.out);
if (System.getProperty("ONLINE_JUDGE") == null) {
System.setIn(new FileInputStream("1"));
}
in = new BufferedReader(new InputStreamReader(System.in, "ISO-8859-9"));
}
String nextString() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(nextString());
}
double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(nextString());
}
public void run() {
try {
initStreams();
double a = nextDouble(), vmax = nextDouble(), l = nextDouble(), d = nextDouble(), w = nextDouble();
if (vmax <= w) {
double v = Math.sqrt(2 * a * l);
if (v <= vmax) {
out(v / a);
} else {
double s = vmax * vmax / (2 * a);
double t = (l - s) / vmax;
out(vmax / a + t);
}
} else {
double v = Math.sqrt(a * d + w * w / 2);
double t1 = 0;
if (w <= Math.sqrt(2 * a * d)) {
if (v <= vmax) {
t1 = v / a + (v - w) / a;
} else {
double s = d - vmax * vmax / (2 * a) - (vmax * vmax - w * w) / (2 * a);
t1 = s / vmax + vmax / a + (vmax - w) / a;
}
} else {
t1 = Math.sqrt(2 * d / a);
w = a * t1;
}
v = Math.sqrt(2 * a * (l - d) + w * w);
double t2 = 0;
if (v <= vmax) {
t2 = (v - w) / a;
} else {
double s = l - d - (vmax * vmax - w * w) / (2 * a);
t2 = (vmax - w) / a + s / vmax;
}
out(t1 + t2);
}
} catch (Throwable e) {
sError = e;
} finally {
pw.flush();
pw.close();
}
}
private void out(double t) {
pw.println(t);
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class RespectTheRules {
private static final double E = 1E-10;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double a = scanner.nextDouble();
double maxV = scanner.nextDouble();
double l = scanner.nextDouble();
double d = scanner.nextDouble();
double w = scanner.nextDouble();
double r = l - d;
w = Math.min(w, maxV);
List<WayPoint> wayPoints = new ArrayList<WayPoint>(256);
double t = 0;
wayPoints.add(new WayPoint(0));
double dW = dTo(w, 0, a);
if (leq(dW, d)) {
wayPoints.add(new WayPoint(w));
{
double v = v(w, a, (d - dW) / 2);
v = Math.min(v, maxV);
wayPoints.add(new WayPoint(v));
wayPoints.add(new WayPoint(w));
double dW_V = dTo(v, w, a);
double vDistance = d - dW - 2 * dW_V;
if (!eq(vDistance)) {
t += vDistance / maxV;
}
}
{
double dW_MaxV = dTo(maxV, w, a);
dW_MaxV = Math.min(dW_MaxV, r);
double v = v(w, a, dW_MaxV);
wayPoints.add(new WayPoint(v));
double dMaxV = r - dW_MaxV;
if (!eq(dMaxV)) {
t += dMaxV / maxV;
}
}
} else {
double dMaxV = dTo(maxV, 0, a);
dMaxV = Math.min(dMaxV, l);
double v = v(0, a, dMaxV);
wayPoints.add(new WayPoint(v));
double dv = l - dMaxV;
if (!eq(dMaxV)) {
t += dv / maxV;
}
}
for (int i = 1; i < wayPoints.size(); ++i) {
double v0 = wayPoints.get(i - 1).v;
double v = wayPoints.get(i).v;
t += Math.abs(tTo(v, v0, a));
}
System.out.println(t);
}
static double tTo(double v, double v0, double a) {
return (v - v0) / a;
}
static double dTo(double v, double v0, double a) {
return (v * v - v0 * v0) / (2 * a);
}
static double v(double v0, double a, double d) {
return Math.sqrt(2 * d * a + v0 * v0);
}
static boolean eq(double value) {
return Math.abs(value) <= E;
}
static boolean l(double v) {
return v < -E;
}
static boolean leq(double v) {
return l(v) || eq(v);
}
static boolean leq(double one, double another) {
return leq(one - another);
}
static class WayPoint {
double v;
WayPoint(double v) {
this.v = v;
}
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main {
private static final double EPS = 1e-11;
public static void main(String[] args) throws IOException {
new Main().run();
}
BufferedReader in;
PrintWriter out;
StringTokenizer st = new StringTokenizer("");
void run() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
double a = nextDouble();
double v = nextDouble();
double l = nextDouble();
double d = nextDouble();
double w = nextDouble();
double ans = 0.0;
if (v < w + EPS || sqr(w) / 2 / a > d - EPS) {
double t1 = sqrt(2 * l / a);
double t2 = v / a;
if (t1 < t2 + EPS) {
ans = t1;
} else {
ans = t2 + (l - a * sqr(t2) / 2) / v;
}
} else {
double t1 = v / a;
double t2 = (v - w) / a;
double s12 = a * sqr(t1) / 2 + w * t2 + a * sqr(t2) / 2;
if (s12 < d + EPS) {
ans += t1 + t2 + (d - s12) / v;
} else {
double ta = sqrt(d / a + sqr(w / a) / 2);
double tb = ta - w / a;
ans += ta + tb;
}
double r = l - d;
double tm = (v - w) / a;
double tx = (sqrt(sqr(w) + 2 * a * r) - w) / a;
if (tx < tm + EPS) {
ans += tx;
} else {
ans += tm + (r - w * tm - a * sqr(tm) / 2) / v;
}
}
out.printf(Locale.US, "%.12f%n", ans);
out.close();
}
double sqr(double x) {
return x * x;
}
String nextToken() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.Scanner;
public class D {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double a = in.nextDouble();
double v = in.nextDouble();
double l = in.nextDouble();
double d = in.nextDouble();
double w = in.nextDouble();
double ans = 0;
double maxSpeedBySign = Math.sqrt(2 * a * d);
double speedAtSign = -1;
if (v <= w) {
if (maxSpeedBySign <= v) {
ans += Math.sqrt(2 * d / a);
speedAtSign = maxSpeedBySign;
} else {
ans += v / a;
double distanceLeftTillSign = d - v * v / a / 2;
ans += distanceLeftTillSign / v;
speedAtSign = v;
}
} else {
if (maxSpeedBySign <= w) {
ans += Math.sqrt(2 * d / a);
speedAtSign = maxSpeedBySign;
} else {
double S = d / 2 - w * w / 4 / a;
double X = d - S;
double speed = Math.sqrt(2 * a * X);
if (speed <= v) {
ans += Math.sqrt(2 * X / a);
ans += (speed - w) / a;
speedAtSign = w;
} else {
double distanceToAc = v * v / a / 2;
double distanceToDe = (v * v - w * w) / a / 2;
ans += Math.sqrt(2 * distanceToAc / a);
ans += (d - distanceToAc - distanceToDe) / v;
ans += (v - w) / a;
}
speedAtSign = w;
}
}
l -= d;
double timeToGetMaxSpeed = (v - speedAtSign) / a;
double timeToReachEnd = (-2 * speedAtSign + Math.sqrt(4 * speedAtSign
* speedAtSign + 8 * a * l))
/ 2 / a;
if (timeToGetMaxSpeed < timeToReachEnd) {
ans += timeToGetMaxSpeed;
double distanceCoveredToMaxSpeed = speedAtSign * timeToGetMaxSpeed
+ 0.5 * a * timeToGetMaxSpeed * timeToGetMaxSpeed;
l -= distanceCoveredToMaxSpeed;
ans += l / v;
} else {
ans += timeToReachEnd;
}
System.out.println(ans);
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.io.*;
import java.util.*;
public class Main {
static boolean LOCAL = System.getSecurityManager() == null;
Scanner sc = new Scanner(System.in);
void run() {
double a = sc.nextDouble(), v = sc.nextDouble();
double L = sc.nextDouble(), d = sc.nextDouble(), w = sc.nextDouble();
w = min(w, v);
double t = 0;
if (w * w / (2 * a) <= d) {
if ((v * v + 2 * v * (v - w) - (v - w) * (v - w)) / (2 * a) <= d) {
t = (2 * v - w) / a + (d - (v * v + 2 * v * (v - w) - (v - w) * (v - w)) / (2 * a)) / v;
} else {
double A = a, B = w, C = (w * w) / (2 * a) - d;
t = w / a + (-B + sqrt(max(0, B * B - A * C))) / A * 2;
}
if ((2 * w * (v - w) + (v - w) * (v - w)) / (2 * a) <= L - d) {
t += (v - w) / a + (L - d - (2 * w * (v - w) + (v - w) * (v - w)) / (2 * a)) / v;
} else {
double A = a, B = w, C = -2 * (L - d);
t += (-B + sqrt(max(0, B * B - A * C))) / A;
}
} else if (v * v / (2 * a) <= L) {
t = v / a + (L - (v * v / (2 * a))) / v;
} else {
t = sqrt(2 * L / a);
}
System.out.printf("%.10f%n", t);
}
class Scanner {
BufferedReader br;
StringTokenizer st;
Scanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
eat("");
}
void eat(String s) {
st = new StringTokenizer(s);
}
String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
boolean hasNext() {
while (!st.hasMoreTokens()) {
String s = nextLine();
if (s == null) return false;
eat(s);
}
return true;
}
String next() {
hasNext();
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
void debug(Object...os) {
System.err.println(deepToString(os));
}
public static void main(String[] args) {
if (LOCAL) {
try {
System.setIn(new FileInputStream("in.txt"));
} catch (Throwable e) {
LOCAL = false;
}
}
if (!LOCAL) {
try {
Locale.setDefault(Locale.US);
System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
} catch (Throwable e) {
}
}
new Main().run();
System.out.flush();
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
import java.util.*;
public class D {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
double f(int dist, double initSp, int a, int maxSp) {
double distToReachMaxSpeed = 0.5 * (maxSp * maxSp - initSp * initSp)
/ a;
if (dist > distToReachMaxSpeed)
return 1d * (maxSp - initSp) / a + (dist - distToReachMaxSpeed)
/ maxSp;
return (Math.sqrt(initSp * initSp + 2 * a * dist) - initSp) / a;
}
void solve() throws IOException {
int a = nextInt();
int maxSp = nextInt();
int len = nextInt();
int signX = nextInt();
int signSp = nextInt();
if (maxSp <= signSp) {
out.printf("%.9f\n", f(len, 0, a, maxSp));
return;
}
double distToReachSignSp = 0.5 * signSp * signSp / a;
if (distToReachSignSp >= signX) {
double t = Math.sqrt(2d * signX / a);
out.printf("%.9f\n", t + f(len - signX, t * a, a, maxSp));
return;
}
double distToReachMaxThenSign = 0.5
* (maxSp * maxSp + maxSp * maxSp - signSp * signSp) / a;
if (distToReachMaxThenSign <= signX) {
double t = 1d * (2 * maxSp - signSp) / a
+ (signX - distToReachMaxThenSign) / maxSp
+ f(len - signX, signSp, a, maxSp);
out.printf("%.9f\n", t);
return;
}
double xSp = Math.sqrt(a * signX + signSp * signSp * 0.5);
double xTime = (2 * xSp - signSp) / a;
out.printf("%.9f\n", xTime + f(len - signX, signSp, a, maxSp));
}
void inp() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new D().inp();
}
String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.nextToken();
}
String nextString() {
try {
return br.readLine();
} catch (IOException e) {
eof = true;
return null;
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
public class d {
double a, v, l, d, w;
private void solve() throws Exception {
a = nextInt(); v = nextInt(); l = nextInt(); d = nextInt(); w = nextInt();
double ans;
if (w >= v){
ans = fromSign(0, l);
}
else{
double tToW = w / a;
double dToW = tToW * tToW * a / 2.;
if (dToW > d){
double curT = Math.sqrt(d * 2. / a);
ans = curT;
double curV = a * curT;
ans += fromSign(curV, l - d);
}
else{
double tToMax = v / a;
double dToMax = tToMax * tToMax * a / 2.;
double tFromMax = (v - w) / a;
double dFromMax = tFromMax * v - tFromMax * tFromMax * a / 2.;
if (dToMax + dFromMax <= d){
ans = tToMax + tFromMax + (d - dToMax - dFromMax) / v;
}
else{
double lo = w, hi = v;
for (int i = 0; i < 1000; ++i){
double mi = (lo + hi) / 2.;
double tTo = mi / a;
double dTo = tTo * tTo * a / 2.;
double tFrom = (mi - w) / a;
double dFrom = tFrom * mi - tFrom * tFrom * a / 2.;
if (dTo + dFrom <= d)
lo = mi;
else
hi = mi;
}
ans = lo / a + (lo - w) / a;
}
ans += fromSign(w, l - d);
}
}
out.printf("%.8f", ans);
}
private double fromSign(double curV, double d) {
double tToMax = (v - curV) / a;
double dToMax = tToMax * curV + tToMax * tToMax * a / 2.;
if (dToMax <= d){
return tToMax + (d - dToMax) / v;
}
else{
double lo = 0, hi = tToMax;
for (int i = 0; i < 1000; ++i){
double mi = (lo + hi) / 2.;
double curD = mi * curV + mi * mi * a / 2.;
if (curD <= d)
lo = mi;
else
hi = mi;
}
return lo;
}
}
public void run() {
try {
solve();
} catch (Exception e) {
NOO(e);
} finally {
out.close();
}
}
PrintWriter out;
BufferedReader in;
StringTokenizer St;
void NOO(Exception e) {
e.printStackTrace();
System.exit(1);
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
String nextToken() {
while (!St.hasMoreTokens()) {
try {
String line = in.readLine();
St = new StringTokenizer(line);
} catch (Exception e) {
NOO(e);
}
}
return St.nextToken();
}
private d(String name) {
try {
in = new BufferedReader(new FileReader(name + ".in"));
St = new StringTokenizer("");
out = new PrintWriter(new FileWriter(name + ".out"));
} catch (Exception e) {
NOO(e);
}
}
private d() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
St = new StringTokenizer("");
out = new PrintWriter(System.out);
} catch (Exception e) {
NOO(e);
}
}
public static void main(String[] args) {
Locale.setDefault(Locale.US);
new d(/*"d"*/).run();
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Stack;
public class ProblemD {
public static void main(String[] args) throws IOException {
BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
String[] data = s.readLine().split(" ");
double a = Double.valueOf(data[0]);
double v = Double.valueOf(data[1]);
String[] line = s.readLine().split(" ");
double l = Double.valueOf(line[0]);
double d = Double.valueOf(line[1]);
double w = Double.valueOf(line[2]);
double ans = solve(a, v, l, d, w);
out.println(String.format("%.07f", ans));
out.flush();
}
private static double solve(double a, double v, double l, double d, double w) {
double maxSpeedAtD = Math.sqrt(2 * d / a) * a;
if (v <= w || maxSpeedAtD <= w) {
// okay. just go
double maxSpeedAtL = Math.sqrt(2 * l / a) * a;
if (maxSpeedAtL <= v) {
return Math.sqrt(2 * l / a);
} else {
double timeToMaxSpeed = v / a;
double leftDist = l - 0.5 * a * timeToMaxSpeed * timeToMaxSpeed;
return timeToMaxSpeed + leftDist / v;
}
}
double time = 0.0d;
double maxSpeedTime = Math.sqrt((d / a) + (w * w / (2 * a * a)));
double maxSpeed = maxSpeedTime * a;
if (maxSpeed <= v) {
time = maxSpeedTime + (a * maxSpeedTime - w) / a;
} else {
double vtime = (2 * a * d + w * w - 2 * v * v) / (2 * a * v);
time = v / a + vtime + (v - w) / a;
}
// after that, just go.
double timeToV = (v - w) / a;
double timeToVLen = timeToV * w + 0.5 * timeToV * (v - w);
if (timeToVLen <= l - d) {
double leftLen = l - d - timeToVLen;
time += timeToV + leftLen / v;
} else {
time += (-w + Math.sqrt(w*w + a * (2 * l - 2 * d))) / a;
}
return time;
}
public static void debug(Object... os){
System.err.println(Arrays.deepToString(os));
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
import java.util.*;
public class Solution {
private BufferedReader in;
private PrintWriter out;
private StringTokenizer st;
void solve() throws IOException {
double a = nextDouble();
double v = nextDouble();
double l = nextDouble();
double d = nextDouble();
double w = nextDouble();
if (w > v) {
w = v;
}
double ans1 = 0.;
double v1;
{
double l_ = 0., r_ = 1e+9;
for (int it = 0; it < 100; ++it) {
double mid = (l_ + r_) / 2.;
double V = a * mid;
double t1 = (V + w) / 2. / a;
double t2 = mid - t1;
t1 = Math.min(t1, v / a);
t2 = Math.min(t2, (v - w) / a);
if (V < w) {
t1 = mid;
t2 = 0.;
}
double dist = t1 * t1 * a / 2. + t2 * (w + t2 * a / 2.) + v * (mid - t1 - t2);
if (dist < d) {
l_ = mid;
} else {
r_ = mid;
}
}
ans1 = (l_ + r_) / 2.;
v1 = Math.min(ans1 * a, w);
}
double ans2 = 0.;
{
double tSp = (v - v1) / a;
double l_ = 0., r_ = 1e+9;
for (int it = 0; it < 100; ++it) {
double mid = (l_ + r_) / 2.;
double dist = Math.min(tSp, mid) * (v1 + Math.min(tSp, mid) * a / 2.);
dist += (mid - Math.min(tSp, mid)) * v;
if (dist < l - d) {
l_ = mid;
} else {
r_ = mid;
}
}
ans2 = (l_ + r_) / 2.;
}
out.println(ans1 + ans2);
}
Solution() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
eat("");
solve();
in.close();
out.close();
}
private void eat(String str) {
st = new StringTokenizer(str);
}
String next() throws IOException {
while (!st.hasMoreTokens()) {
String line = in.readLine();
if (line == null) {
return null;
}
eat(line);
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static void main(String[] args) throws IOException {
new Solution();
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;
public class Main {
void solve() {
double a = sc.nextDouble();
double v = sc.nextDouble();
double l = sc.nextDouble();
double d = sc.nextDouble();
double w = sc.nextDouble();
double res = calc(a, v, l, d, w);
out.printf("%.10f\n", res);
}
double calc(double a, double v, double l, double d, double w) {
if (v <= w) return getTime(a, 0, l, v);
// 距離 d までに速度 w に達しない場合
if ((w * w) >= d * 2 * a) return getTime(a, 0, l, v);
// それ以外は、d は速度wで通過
double ans = 0;
double[] r1 = getReach(a, 0, v);
double[] r2 = getReach(a, w, v);
// d までに最高速度 v に達する場合
if (r1[1] + r2[1] <= d) {
ans += r1[0];
ans += r2[0];
ans += (d - r1[1] - r2[1]) / v;
} else {
// d までに最高速度に達しない場合
double t0 = sqrt((2 * a * d + w * w) / (2 * a * a));
ans += t0 + (a * t0 - w) / a;
}
ans += getTime(a, w, l - d, v);
return ans;
}
/**
* s から v に達するまでの時間と、その間の走行距離
*/
double[] getReach(double a, double s, double v) {
double t = (v - s) / a;
double dist = t * (v + s) / 2.0;
return new double[]{t, dist};
}
/**
* 初速 s、加速a、 最高速度 v で距離 l を走るのにかかる時間
*/
double getTime(double a, double s, double l, double v) {
double t = (-s + sqrt(s * s + 2 * a * l)) / a;
double t_ = (v - s) / a;
if (t < t_) return t;
double p = l - (s + v) * t_ / 2;
return t_ + (p / v);
}
public static void main(String[] args) throws Exception {
Class<?> here = new Object(){}.getClass().getEnclosingClass();
try {
String packageName = here.getPackage().getName();
packageName = "src/" + packageName.replaceAll("\\.", "/") + "/";
System.setIn(new FileInputStream(packageName + "input.txt"));
// System.setOut(new PrintStream(new FileOutputStream(packageName + "output.txt")));
} catch (FileNotFoundException e) {
} catch (NullPointerException e) {
}
Object o = Class.forName(here.getName()).newInstance();
o.getClass().getMethod("run").invoke(o);
}
static void tr(Object... os) {
System.err.println(deepToString(os));
}
MyScanner sc = null;
PrintWriter out = null;
public void run() throws Exception {
sc = new MyScanner(System.in);
out = new PrintWriter(System.out);
for (;sc.hasNext();) {
solve();
out.flush();
}
out.close();
}
void print(int[] a) {
out.print(a[0]);
for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
out.println();
}
class MyScanner {
String line;
BufferedReader reader;
StringTokenizer tokenizer;
public MyScanner(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public void eat() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
line = reader.readLine();
if (line == null) {
tokenizer = null;
return;
}
tokenizer = new StringTokenizer(line);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public String next() {
eat();
return tokenizer.nextToken();
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public boolean hasNext() {
eat();
return (tokenizer != null && tokenizer.hasMoreElements());
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.*;
import java.io.*;
public class Main {
static final double EPS = 1E-6;
double a, v, l, d, w, u;
public void run() {
a = cin.nextDouble();
v = cin.nextDouble();
l = cin.nextDouble();
d = cin.nextDouble();
w = cin.nextDouble();
w = Math.min(w, v);
double s1 = v * v / (2 * a);
double s2 = w * w / (2 * a);
double s3 = s1 - s2;
double cost = 0;
if (d < s2) {
cost += Math.sqrt(2 * d / a);
w = cost * a;
} else if (d < s1 + s3) {
u = Math.sqrt(d / a + w * w / (2 * a * a)) * a;
cost = u / a + (u - w) / a;
} else {
cost += v / a;
cost += (v - w) / a;
cost += (d - s3 - s1) / v;
}
d = l - d;
s3 = (v * v - w * w) / (2 * a);
if (d < s3) {
cost += (-w + Math.sqrt(w * w + 2 * a * d)) / a;
} else {
cost += (v - w) / a;
cost += (d - s3) / v;
}
out.println(cost);
}
public static void main(String[] args) throws IOException {
Main sloved = new Main();
sloved.run();
sloved.out.close();
}
Scanner cin = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.*;
import static java.lang.Math.*;
public final class FollowTrafficRules {
private static double[] acce(double i, double a, double v) {
double[] r = new double[2];
r[0] = (v - i)/a;
r[1] = 1d/2d * a * pow(r[0], 2) + i * r[0];
return r;
}
private static double solve(double i, double a, double l) {
double e = sqrt(pow(i, 2) + 2d * a * l);
e = a > 0 ? e : -1d * e;
return (e - i)/a;
}
private static double time(double i, double a, double v, double l) {
double[] r = acce(i, a, v);
if (r[1] >= l) return solve(i, a, l);
return r[0] + (l - r[1])/v;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a = sc.nextDouble();
double v = sc.nextDouble();
double l = sc.nextDouble();
double d = sc.nextDouble();
double w = sc.nextDouble();
double t = 0d;
if (v <= w) t = time(0, a, v, l);
else {
double[] r = acce(0, a, w);
if (r[1] >= d) t = time(0, a, v, l);
else {
t += r[0];
t += 2d * time(w, a, v, (d - r[1])/2d);
t += time(w, a, v, l - d);
}
}
System.out.println(t);
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
import java.util.*;
public class D implements Runnable {
public static void main(String[] args) {
new Thread(new D()).start();
}
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return "0";
}
}
return st.nextToken();
}
public void run() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.flush();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
static final double EPS = 1e-9;
static double qEq(double a, double b, double c) {
double d = b * b - 4 * a * c;
if (d < -EPS) {
return Double.NaN;
}
return Math.max((-b + Math.sqrt(d)) / (2 * a), (-b - Math.sqrt(d))
/ (2 * a));
}
static int compare(double a, double b) {
return Math.abs(a - b) < EPS ? 0 : Double.compare(a, b);
}
void solve() {
double a = nextDouble();
double v = nextDouble();
double l = nextDouble();
double d = nextDouble();
double w = nextDouble();
if (compare(w, v) >= 0) {
double t1 = v / a;
double d1 = a * t1 * t1 * .5;
if (compare(d1, l) >= 0) {
out.println(Math.sqrt(2 * l / a));
} else {
out.println(t1 + (l - d1) / v);
}
return;
}
double t1 = w / a;
double d1 = a * t1 * t1 * .5;
if (compare(d1, d) >= 0) {
double t2 = v / a;
double d2 = a * t2 * t2 * .5;
if (compare(d2, l) >= 0) {
out.println(Math.sqrt(2 * l / a));
} else {
out.println(t2 + (l - d2) / v);
}
return;
}
double left = d - d1;
double timeToV = (v - w) / a;
double distToV = a * timeToV * timeToV * .5 + w * timeToV;
// System.err.println(t1 + " " + left + " " + timeToV + " " + distToV
// + " " + d1);
if (compare(distToV, left * .5) >= 0) {
double t2 = qEq(a * .5, w, -left * .5);
// System.err.println(t2 + " " + (a * t2 * t2 * .5 + w * t2));
t2 += t1 + t2;
if (compare(distToV, l - d) >= 0) {
out.println(t2 + qEq(a * .5, w, d - l));
} else {
out.println(t2 + timeToV + (l - d - distToV) / v);
}
return;
}
double t2 = t1 + 2 * timeToV + (left - 2 * distToV) / v;
if (compare(distToV, l - d) >= 0) {
out.println(t2 + qEq(a * .5, w, d - l));
} else {
out.println(t2 + timeToV + (l - d - distToV) / v);
}
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
import java.util.*;
import java.text.*;
public class FollowTrafficRules
{
public Scanner in = new Scanner(System.in);
public PrintStream out = System.out;
public double len, d, w, vmax, a;
DecimalFormat fmt = new DecimalFormat("0.0000000000000000");
public void main()
{
a = in.nextDouble();
vmax = in.nextDouble();
len = in.nextDouble();
d = in.nextDouble();
w = in.nextDouble();
out.println(fmt.format(T()));
}//end public void main()
public double T()
{
double t, s;
double t1, s1;
t1 = vmax / a;
s1 = vmax*vmax/(2.0*a);
double t3, s3;
t3 = w/a;
s3 = w*w/(2.0*a);
if(w >= vmax)
{
if(s1 < len)
{
return t1 + (len - s1)/vmax;
}
else
{
return Math.sqrt(2.0*len/a);
}
}
else
{
//w < vmax
double t2, s2, v2;
t2 = Math.sqrt(2.0*d/a);
v2 = a*t2;
double tx, vx;
vx = Math.sqrt((2.0*a*d + w*w)/2.0);
tx = vx / a;
//vmax > w
//v2 > vx > w
if(v2 < w)
{
if(v2 > vmax)
{
//v2 > vmax > w
if(vmax > vx)
{
return tx + (vx - w)/a + T2(w);
}
else
{
double ty, sy;
ty = (vmax - w)/a;
sy = ty * (vmax + w)/2.0;
return t1 + ty + (d - s1 - sy)/vmax + T2(w);
}
}
else
{
//v2 < w, v2 <= vmax
return t2 + T2(v2);
}
}
else if(v2 > vmax) //v2 >= w, vmax > w
{
//v2 > vmax > w
if(vmax > vx)
{
return tx + (vx - w)/a + T2(w);
}
else
{
double ty, sy;
ty = (vmax - w)/a;
sy = ty * (vmax + w)/2.0;
return t1 + ty + (d - s1 - sy)/vmax + T2(w);
}
}
else //vmax >= v2 >= w
{
//out.println("Questionable.");
//return binary() + T2(w);
//return t3 + (d-s3)/w + T2(w);
return tx + (vx - w)/a + T2(w);
}
}
}
public double binary()
{
double low, high, t, s;
low = 0.0; high = vmax/a;
for(int c=0;c<50;++c)
{
t = (low+high)/2;
s = (a*t*t)/2 + ((a*t - w)/a)*(a*t + w)/2.0;
if(s > d) high = t;
else low = t;
}
t = (low+high)/2;
return t + (a*t - w)/a;
}
/*
public double T()
{
double t1, s1, tx, sx, vx, ty, vy, sz, tz;
t1 = vmax / a;
s1 = a*t1*t1 / 2.0;
vx = Math.sqrt((2.0*a*d + w*w)/2.0);
tx = vx / a;
if(s1 < d)
{
//reaches vmax
if(vx < vmax)
{
//stops at vx
return tx + (vx - w)/a + T2(w);
}
else //vx >= vmax
{
//stops at vmax
if(w > vmax)
{
return t1 + (d - s1)/vmax + T2(vmax);
}
else
{
tz = (vmax - w)/a;
sz = ((vmax + w)/2.0) * tz;
return t1 + (d-sz-s1)/vmax + tz + T2(w);
}
}
}
else //s1 >= d
{
//never reaches vmax
vy = Math.sqrt(2.0*d*a);
ty = vy / a;
if(vx < vy)
{
//stops at vx
return tx + (vx - w)/a + T2(w);
}
else //vx >= vy
{
if(w < vy)
{
return w/a + (d - w*w/(2.0*a))/w + T2(w);
}
else //w >= vy
{
//goes to vy, accelerate all the way
return ty + T2(vy);
}
}
}
}
*/
public double T2(double v0)
{
//v0 <= min(w, vmax)
double t1, s1;
t1 = (vmax - v0)/a;
s1 = ((vmax + v0)/2.0)*t1;
if(s1 < len-d)
{
//reaches vmax
return t1 + (len-d-s1)/vmax;
}
else //s1 >= len - d
{
//does not reach vmax
return (-v0 + Math.sqrt(v0*v0 + 2*a*(len-d)))/a;
}
}
public static void main(String[] args)
{
(new FollowTrafficRules()).main();
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Scanner;
public class Main implements Runnable {
/**
* @param args
*/
public static void main(String[] args) {
new Thread(new Main()).start();
}
public void run() {
Locale.setDefault(Locale.US);
try {
run1();
} catch (IOException e) {
throw new RuntimeException();
}
}
int nextInt(StreamTokenizer st) throws IOException {
st.nextToken();
return (int) st.nval;
}
double nextDouble(StreamTokenizer st) throws IOException {
st.nextToken();
return st.nval;
}
String nextLine(StreamTokenizer st) throws IOException {
st.nextToken();
return st.sval;
}
Map<String, BigInteger> map = new HashMap<String, BigInteger>();
public void run1() throws IOException {
Locale.setDefault(Locale.US);
// long time = -System.currentTimeMillis();
Scanner sc = new Scanner(new InputStreamReader(System.in));
// BufferedReader br = new BufferedReader(new
// InputStreamReader(System.in));
// Scanner sc = new Scanner(new File("input.txt"));
// BufferedReader br = new BufferedReader(new FileReader("input.txt"));
// PrintStream ps = System.out;// new PrintStream(new
// File("output.txt"));
// gopa(br, ps);
double a = sc.nextDouble();
double vmax = sc.nextDouble();
double l2 = sc.nextDouble();
double l1 = sc.nextDouble();
l2 -= l1;
double boundv = sc.nextDouble();
if (boundv >= vmax || boundv * boundv / a / 2 > l1) {
System.out.print(get(0, a, vmax, l1 + l2));
System.exit(0);
}
double tmplen = vmax * vmax / a / 2 + (vmax + boundv) / 2
* (vmax - boundv) / a;
if (tmplen < l1) {
System.out.print(get(boundv, a, vmax, l2) + vmax
/ a + (vmax - boundv) / a + (l1 - tmplen) / vmax);
System.exit(0);
}
double v = Math.sqrt(l1 * a + boundv * boundv / 2);
System.out.print(get(boundv, a, vmax, l2) + v / a
+ (v - boundv) / a);
}
double get(double v0, double a, double vmax, double l) {
double tmplen = (vmax + v0) / 2 * (vmax - v0) / a;
// System.out.println(tmplen);
if (l >= tmplen) {
return (vmax - v0) / a + (l - tmplen) / vmax;
}
return (-v0 + Math.sqrt(v0 * v0 + 2 * a * l)) / a;
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;
public class ProblemD_05 {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
void init() throws FileNotFoundException{
if (ONLINE_JUDGE){
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}else{
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
}
String readString() throws IOException{
while(!tok.hasMoreTokens()){
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
int readInt() throws IOException{
return Integer.parseInt(readString());
}
long readLong() throws IOException{
return Long.parseLong(readString());
}
double readDouble() throws IOException{
return Double.parseDouble(readString());
}
public static void main(String[] args){
new ProblemD_05().run();
}
public void run(){
try{
long t1 = System.currentTimeMillis();
init();
solve();
out.close();
long t2 = System.currentTimeMillis();
System.err.println("Time = "+(t2-t1));
}catch (Exception e){
e.printStackTrace(System.err);
System.exit(-1);
}
}
void solve() throws IOException{
double a = readDouble();
double v = readDouble();
double l = readDouble();
double d = readDouble();
double w = readDouble();
double t = 0;
double td = d > v * v / (2 * a)? v / a + (d - v * v / (2 * a)) / v: sqrt(2 *d / a);
if (w >= min(a * td, v)){
t += td;
w = min(a * td, v);
}else{
double v0 = sqrt(w * w / 2 + a * d);
if (v0 * v0 <= v * v){
t += (2 * v0 - w) / a;
}else{
t += (2 * v - w) / a;
double s2 = d - (2 * v * v - w * w) / (2 * a);
t += s2 / v;
}
}
double t1 = (sqrt(w * w + 2 * a * (l - d)) - w) / a;
if (t1 > (v - w) / a) t1 = (v - w) / a;
t += t1;
double s1 = w * t1 + a * t1 * t1 / 2;
double t2 = (l - d - s1) / v;
t += t2;
out.printf(Locale.US, "%.12f", t);
}
static int[][] step8 = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}};
static int[][] stepKnight = {{-2, -1}, {-2, 1}, {-1, -2}, {-1, 2}, {1, -2}, {1, 2}, {2, -1}, {2, 1}};
static long gcd(long a, long b){
if (a == 0) return b;
return gcd(b % a, a);
}
static long lcm(long a, long b){
return a / gcd(a, b)*b;
}
static long[] gcdPlus(long a, long b){
long[] d = new long[3];
if (a == 0){
d[0] = b;
d[1] = 0;
d[2] = 1;
}else{
d = gcdPlus(b % a, a);
long r = d[1];
d[1] = d[2] - b/a*d[1];
d[2] = r;
}
return d;
}
static long binpow(long a, int n){
if (n == 0) return 1;
if ((n & 1) == 0){
long b = binpow(a, n/2);
return b*b;
}else return binpow(a, n - 1)*a;
}
static long binpowmod(long a, int n, long m){
if (m == 1) return 0;
if (n == 0) return 1;
if ((n & 1) == 0){
long b = binpowmod(a, n/2, m);
return (b*b) % m;
}else return binpowmod(a, n - 1, m)*a % m;
}
static long phi(long n){
int[] p = Sieve((int)ceil(sqrt(n)) + 2);
long phi = 1;
for (int i = 0; i < p.length; i++){
long x = 1;
while (n % p[i] == 0){
n /= p[i];
x *= p[i];
}
phi *= x - x/p[i];
}
if (n != 1) phi *= n - 1;
return phi;
}
static long f(long n, int x, int k){ //Кол-во десятичных чисел (включая 0), содержащих в себе цифры от 0 до k-1
if (n == 0) return 1;
long b = binpow(10, x - 1);
long c = n / b;
return (c < k? c: k)*binpow(k, x - 1) + (c < k? 1: 0)*f(n % b, x - 1, k);
}
static long fib(int n){
if (n == 0) return 0;
if ((n & 1) == 0){
long f1 = fib(n/2 - 1);
long f2 = fib(n/2 + 1);
return f2*f2 - f1*f1;
}else{
long f1 = fib(n/2);
long f2 = fib(n/2 + 1);
return f1*f1 + f2*f2;
}
}
static BigInteger BigFib(int n){
if (n == 0) return BigInteger.ZERO;
if ((n & 1) == 0){
BigInteger f1 = BigFib(n/2 - 1);
f1 = f1.multiply(f1);
BigInteger f2 = BigFib(n/2 + 1);
f2 = f2.multiply(f2);
return f2.subtract(f1);
}else{
BigInteger f1 = BigFib(n/2);
f1 = f1.multiply(f1);
BigInteger f2 = BigFib(n/2 + 1);
f2 = f2.multiply(f2);
return f2.add(f1);
}
}
static public class PointD{
double x, y;
public PointD(double x, double y){
this.x = x;
this.y = y;
}
}
static double d(Point p1, Point p2){
return sqrt(d2(p1, p2));
}
static public double d(PointD p1, PointD p2){
return sqrt(d2(p1, p2));
}
static double d2(Point p1, Point p2){
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}
static public double d2(PointD p1, PointD p2){
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}
static boolean IsProbablyPrime(long n){
if (n == 1) return false;
if ((n & 1) == 0) return false;
for (int j = 3; j < sqrt(n) + 1; j += 2){
if (n % j == 0) return false;
}
return true;
}
static int[] Sieve(int n){
boolean[] b = new boolean[n+1];
Arrays.fill(b, true);
b[0] = false;
b[1] = false;
long nLong = n;
int j=0;
for (int i = 1; i <= n; i++) {
if (b[i]){
j++;
if (((long)i)*i <= nLong) {
for (int k = i*i; k <= n; k += i) {
b[k] = false;
}
}
}
}
int[] p = new int[j];
Arrays.fill(p, 0);
j=0;
for (int i = 2; i <= n; i++) {
if (b[i]){
p[j]=i;
j++;
}
}
return p;
}
static int[][] Palindromes(String s){
char[] c = s.toCharArray();
int n = c.length;
int[][] d = new int[2][n];
int l = 0, r = -1;
for (int i = 0; i < n; i++){
int j = (i > r? 0: min(d[0][l+r-i+1], r-i+1)) + 1;
for (; i - j >= 0 && i + j - 1< n && c[i-j] == c[i+j-1]; j++);
d[0][i] = --j;
if (i + d[0][i] - 1 > r){
r = i + d[0][i] - 1;
l = i - d[0][i];
}
}
l = 0;
r = -1;
for (int i = 0; i < n; i++){
int j = (i > r? 0: min(d[1][l+r-i], r-i)) + 1;
for (; i - j >= 0 && i + j < n && c[i-j] == c[i+j]; j++);
d[1][i] = --j;
if (i + d[1][i] > r){
r = i + d[1][i];
l = i - d[1][i];
}
}
return d;
}
static public class Permutation {
int[] a;
int n;
public Permutation(int n){
this.n=n;
a=new int[n];
for (int i=0; i<n; i++){
a[i]=i;
}
}
public boolean nextPermutation(){ //Пишется с do{}while(nextPermutation(a));
int i=n-1;
for (i=n-2; i>=0; i--){
if (a[i]<a[i+1]){
break;
}
}
if (i==-1){
return false;
}
int jMin=i+1;
for (int j=n-1; j>i; j--){
if (a[i]<a[j]&&a[j]<a[jMin]){
jMin=j;
}
}
swap(i, jMin);
for (int j=1; j<=(n-i)/2; j++){
swap(i+j, n-j);
}
return true;
}
public int get(int i){
return a[i];
}
void swap(int i, int j){
int r=a[i];
a[i]=a[j];
a[j]=r;
}
}
static public class Fraction implements Comparable<Fraction>, Cloneable{
public final Fraction FRACTION_ZERO = new Fraction();
public final Fraction FRACTION_ONE = new Fraction(1);
public long numerator = 0;
public long denominator = 1;
public Fraction(){
numerator = 0;
denominator = 1;
}
public Fraction(long numerator){
this.numerator = numerator;
denominator = 1;
}
public Fraction(long numerator, long denominator){
this.numerator = numerator;
this.denominator = denominator;
Cancellation();
}
public Fraction(double numerator, double denominator, int accuracy){
this.numerator = (long)(numerator*pow(10,accuracy));
this.denominator = (long)(denominator*pow(10,accuracy));
Cancellation();
}
public Fraction(String s){
if (s.charAt(0) == '-'){
denominator = -1;
s = s.substring(1);
}
if (s.indexOf("/") != -1){
denominator *= Integer.parseInt(s.substring(s.indexOf("/") + 1));
}
if (s.indexOf(" ") != -1){
numerator = Integer.parseInt(s.substring(0, s.indexOf(" "))) * abs(denominator) + Integer.parseInt(s.substring(s.indexOf(" ") + 1, s.indexOf("/")));
}else{
if (s.indexOf("/") != -1){
numerator = Integer.parseInt(s.substring(0, s.indexOf("/")));
}else{
numerator = Integer.parseInt(s)*abs(denominator);
}
}
this.Cancellation();
}
void Cancellation(){
long g = gcd(abs(numerator), abs(denominator));
numerator /= g;
denominator /= g;
if (denominator < 0){
numerator *= -1;
denominator *= -1;
}
}
public String toString(){
String s = "";
if (numerator == 0){
return "0";
}
if (numerator < 0){
s += "-";
}
if (abs(numerator) >= denominator){
s += Long.toString(abs(numerator) / denominator) + " ";
}
if (abs(numerator) % denominator != 0){
s += Long.toString(abs(numerator) % denominator);
}else{
s = s.substring(0, s.length()-1);
}
if (denominator != 1){
s += "/" + Long.toString(denominator);
}
return s;
}
public Fraction add(Fraction f){
Fraction fResult = new Fraction();
fResult.denominator = lcm(denominator, f.denominator);
fResult.numerator = numerator * fResult.denominator / denominator + f.numerator * fResult.denominator / f.denominator;
fResult.Cancellation();
return fResult;
}
public Fraction subtract(Fraction f){
Fraction fResult = new Fraction();
fResult.denominator = lcm(denominator, f.denominator);
fResult.numerator = numerator * fResult.denominator / denominator - f.numerator * fResult.denominator / f.denominator;
fResult.Cancellation();
return fResult;
}
public Fraction multiply(Fraction f){
Fraction fResult = new Fraction();
fResult.numerator = numerator * f.numerator;
fResult.denominator = denominator * f.denominator;
fResult.Cancellation();
return fResult;
}
public Fraction divide(Fraction f){
Fraction fResult = new Fraction();
fResult.numerator = numerator * f.denominator;
fResult.denominator = denominator * f.numerator;
fResult.Cancellation();
return fResult;
}
@Override
public int compareTo(Fraction f){
long g = gcd(denominator, f.denominator);
long res = numerator * (f.denominator / g) - f.numerator * (denominator / g);
if (res < 0){
return -1;
}
if (res > 0){
return 1;
}
return 0;
}
public Fraction clone(){
Fraction fResult = new Fraction(numerator, denominator);
return fResult;
}
public Fraction floor(){
Fraction fResult = this.clone();
fResult.numerator = (fResult.numerator / fResult.denominator) * fResult.denominator;
return fResult;
}
public Fraction ceil(){
Fraction fResult = this.clone();
fResult.numerator = (fResult.numerator/fResult.denominator + 1) * fResult.denominator;
return fResult;
}
public Fraction binpow(int n){
if (n==0) return FRACTION_ONE;
if ((n&1)==0){
Fraction f=this.binpow(n/2);
return f.multiply(f);
}else return binpow(n-1).multiply(this);
}
}
static public class FenwickTree_1{ //One-dimensional array
int n;
long[] t;
public FenwickTree_1(int n){
this.n = n;
t = new long[n];
}
public long sum(int xl, int xr){
return sum(xr) - sum(xl);
}
public long sum(int x){
long result = 0;
for (int i = x; i >= 0; i = (i & (i + 1)) - 1){
result += t[i];
}
return result;
}
public void update(int x, long delta){
for (int i = x; i < n; i = (i | (i + 1))){
t[i] += delta;
}
}
}
static public class FenwickTree_2{ //Two-dimensional array
int n, m;
long[][] t;
public FenwickTree_2(int n, int m){
this.n = n;
this.m = m;
t = new long[n][m];
}
public long sum(int xl, int yl, int xr, int yr){
return sum(xr, yr) - sum(xl - 1, yr) - sum(xr, yl - 1) + sum(xl - 1, yl - 1);
}
public long sum(int x, int y){
long result = 0;
for (int i = x; i >= 0; i = (i & (i + 1)) - 1){
for (int j = y; j >= 0; j = (j & (j + 1)) - 1){
result+=t[i][j];
}
}
return result;
}
public void update(int x, int y, long delta){
for (int i = x; i < n; i = (i | (i + 1))){
for (int j = y; j < m; j = (j | (j + 1))){
t[i][j] += delta;
}
}
}
}
static public class FenwickTree_3{ //Three-dimensional array
int n, m, l;
long[][][] t;
public FenwickTree_3(int n, int m, int l){
this.n = n;
this.m = m;
this.l = l;
t = new long[n][m][l];
}
public long sum(int xl, int yl, int zl, int xr, int yr, int zr){
return sum(xr, yr, zr) - sum(xl - 1, yr, zr)
+ sum(xl - 1, yr, zl - 1) - sum(xr, yr, zl - 1)
- sum(xr, yl - 1, zr) + sum(xl - 1, yl - 1, zr)
- sum(xl - 1, yl - 1, zl - 1) + sum(xr, yl - 1, zl - 1);
}
public long sum(int x, int y, int z){
long result = 0;
for (int i = x; i >= 0; i = (i & (i + 1)) - 1){
for (int j = y; j >= 0; j = (j & (j + 1)) - 1){
for (int k = z; k >= 0; k = (k & (k + 1)) - 1){
result += t[i][j][k];
}
}
}
return result;
}
public void update(int x, int y, int z, long delta){
for (int i = x; i < n; i = (i | (i + 1))){
for (int j = y; j < n; j = (j | (j + 1))){
for (int k = z; k < n; k = (k | (k + 1))){
t[i][j][k] += delta;
}
}
}
}
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.Scanner;
public class D
{
public static void main(String[] args)
{
new D();
}
D()
{
Scanner in = new Scanner(System.in);
double a = in.nextDouble();
double v = in.nextDouble();
double l = in.nextDouble();
double d = in.nextDouble();
double w = in.nextDouble();
if (w>v) w=v;
double dx=(v*v-w*w)/(2*a);
double d0=(w*w)/(2*a);
double t=0;
if (d0>d) // doesn't make it to speed w before reaching d
{
if (d0>=l) // never gets to speed w
{
t=Math.sqrt(2*a*l)/a;
}
else
{
t=w/a;
if (d0+dx>=l) // never gets to speed v
{
t+=(-w+Math.sqrt(w*w+2*a*(l-d0)))/a;
}
else // makes it to speed v
{
t+=(v-w)/a;
t+=(l-(d0+dx))/v;
}
}
}
else // makes it to speed w before reachig d
{
t=w/a; // get up to speed w
// get time after reaching d
if (d+dx>l) // never makes it back to v after reaching d
{
t+=(-w+Math.sqrt(w*w+2*a*(l-d)))/a;
}
else // makes it to speed v after reaching d
{
t+=(v-w)/a;
t+=(l-(d+dx))/v;
}
// handle getting to d
if (d0+2*dx>d) // can't get to v before reaching d
{
double half=(d-d0)/2;
t+=2*(-w+Math.sqrt(w*w+2*a*half))/a;
}
else // can get to v before reaching d
{
t+=2*(v-w)/a;
t+=(d-2*dx-d0)/v;
}
}
System.out.printf("%.12f%n", t+1e-11);
}
}
| constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.io.*;
import java.util.*;
public class trafficerules {
public static void main(String[] args) throws Exception {
if ("Satayev".equals(System.getProperty("user.name"))) {
long start = System.nanoTime();
new trafficerules().solve(new FileInputStream("input"));
System.err.printf("Time elapsed: %d ms.\n", (System.nanoTime()-start)/1000000);
}
else
new trafficerules().solve(System.in);
}
void solve(InputStream is) throws Exception {
Scanner in = new Scanner(is);
double a = in.nextDouble(), maxv = in.nextDouble(), s = in.nextDouble(), d = in.nextDouble(), w = in.nextDouble();
if (maxv < w)
w = maxv;
double t = 0;
// v = at
// s = att/2
double t1 = w / a;
double s1 = a*t1*t1/2;
double v1 = w;
if ( s1 < d ) {
v1 = w;
if (v1 >= maxv)
t1 += (d-s1)/v1;
else {
double tt = (maxv - v1)/a;
double ss = v1*tt+a*tt*tt/2;
ss *= 2;
if (s1 + ss < d)
t1 += tt*2 + (d-s1-ss)/maxv;
else {
ss = (d-s1)/2;
// ss = v1*t + a*t*t/2;
double A = a/2;
double B = v1;
double C = -ss;
double D = B*B - 4 * A * C;
tt = (-B + Math.sqrt(D))/2/A;
t1 += tt*2;
}
}
s1 = d;
}
if (s1 > d) {
s1 = d;
t1 = Math.sqrt(2*s1/a);
v1 = a * t1;
}
t += t1;
double t2 = (maxv - v1) / a;
double s2 = v1*t2 + a*t2*t2/2;
double v2 = maxv;
if (s1 + s2 < s) {
v2 = maxv;
t2 += (s-s1-s2)/v2;
}
if (s1 + s2 > s) {
s -= s1;
// v = v1 + a*t
// s = v1*t + a*t*t/2
double A = a/2;
double B = v1;
double C = -s;
double D = B*B - 4*A*C;
t2 = (-B + Math.sqrt(D))/2/A;
}
t += t2;
System.out.println(t);
}
} | constant | 5_D. Follow Traffic Rules | CODEFORCES |
import java.util.Scanner;
public class AlexAndARhombus {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
System.out.println(n*n+(n-1)*(n-1));
sc.close();
}
}
| constant | 1180_A. Alex and a Rhombus | CODEFORCES |
import java.util.*;
import java.io.*;
public class A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
long n = s.nextLong();
if(n >= 0)
System.out.println(n);
else {
String str = ("" + n).substring(1);
if(str.length() == 1)
System.out.println("-" + str);
else {
long one = Long.parseLong(str.substring(0, str.length()-1));
long two = Long.parseLong(str.substring(0, str.length()-2) + str.substring(str.length()-1));
if(one > two)
System.out.println((two!=0?"-":"") + two);
else
System.out.println((one!=0?"-":"") + one);
}
}
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main implements Runnable {
PrintWriter out;
Scanner in;
public static void main(String[] args) throws IOException {
new Thread(new Main()).start();
}
public void run() {
try {
out = new PrintWriter(new BufferedOutputStream(System.out));
in = new Scanner(System.in);
solve();
out.close();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
public void solve() throws IOException {
int n = in.nextInt();
if (n >= 0) {
out.println(n);
} else {
String s = String.valueOf(n);
int l = s.length();
String s1 = s.substring(0, l - 2);
if (s.charAt(l - 1) > s.charAt(l - 2)) {
s1 += s.charAt(l - 2);
} else {
s1 += s.charAt(l - 1);
}
out.println(Integer.parseInt(s1));
}
}
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int res = n;
String str = Integer.toString(n);
res = Math.max(res, Integer.parseInt(str.substring(0, str.length() - 1)));
res = Math.max(res, Integer.parseInt(str.substring(0, str.length() - 2) + str.substring(str.length() - 1)));
System.out.println(res);
}
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.util.Scanner;
public class Main2 {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
String st = input.nextLine();
System.out.println(bank(st));
}
public static int bank(String st){
StringBuilder sb = new StringBuilder(st);
int st1 = Integer.parseInt(sb.substring(0,st.length()-2)+sb.substring(st.length()-1,st.length()));
int st2 = Integer.parseInt(sb.substring(0,st.length()-1));
int st3 = Integer.parseInt(st);
return Math.max(st3,Math.max(st1, st2));
}
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.util.*;
import java.io.*;
public class ProbA {
int account;
void start(Scanner sc, PrintStream out) {
int ans = 0;
account = sc.nextInt();
int account1 = account / 10;
int account2 = (account - (account % 100)) / 10 + (account % 10);
out.println(Math.max(account1, Math.max(account, account2)));
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintStream out = System.out;
new ProbA().start(sc, out);
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A {
static class Scanner{
BufferedReader br=null;
StringTokenizer tk=null;
public Scanner(){
br=new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException{
while(tk==null || !tk.hasMoreTokens())
tk=new StringTokenizer(br.readLine());
return tk.nextToken();
}
public int nextInt() throws NumberFormatException, IOException{
return Integer.valueOf(next());
}
public double nextDouble() throws NumberFormatException, IOException{
return Double.valueOf(next());
}
}
public static void main(String args[]) throws NumberFormatException, IOException{
Scanner sc = new Scanner();
int T = sc.nextInt();
if ( T > 0)
System.out.println(T);
else{
String cad = (T + "");
int min = Math.min(cad.charAt(cad.length() - 1) - '0', cad.charAt(cad.length() - 2) - '0');
if (min == 0 && cad.length() == 3)
System.out.println(0);
else
System.out.println(cad.substring(0, cad.length() - 2) + "" + min);
}
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class A {
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter out;
public void solve() throws IOException {
int N = nextInt();
if( N >= 0) {
out.println(N);
return;
}
int ans = N/10;
int ans2 = N/100*10 + N%10;
out.println( Math.max(ans, ans2));
}
/**
* @param args
*/
public static void main(String[] args) {
new A().run();
}
public void run() {
try {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
out = new PrintWriter(System.out);
solve();
reader.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.IOException;
import java.util.Locale;
import java.util.Scanner;
public class A {
public void processInput() throws IOException {
Scanner in = new Scanner(System.in);
long n = in.nextLong();
long res = go(n);
System.out.printf(Locale.ENGLISH, "%d\n", res);
in.close();
}
public long go(long n) {
long res = n;
String str = String.valueOf(n);
StringBuilder sb = new StringBuilder(str);
sb.deleteCharAt(str.length() - 1);
if (sb.length() > 0 && !sb.toString().equals("-")) {
res = Math.max(res, Long.valueOf(sb.toString()));
}
if (str.length() > 1) {
if (str.charAt(str.length() - 2) != '-') {
sb = new StringBuilder(str);
sb.deleteCharAt(str.length() - 2);
res = Math.max(res, Long.valueOf(sb.toString()));
}
}
return res;
}
public static void main(String[] args) throws Exception {
A a = new A();
a.processInput();
}
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.util.*;
/**
*
* @author N-AssassiN
*/
public class Main {
private static BufferedReader reader;
private static BufferedWriter out;
private static StringTokenizer tokenizer;
//private final static String filename = "filename";
private static void init(InputStream input, OutputStream output) {
reader = new BufferedReader(new InputStreamReader(input));
out = new BufferedWriter(new OutputStreamWriter(output));
//reader = new BufferedReader(new FileReader(filename + ".in"));
//out = new BufferedWriter(new FileWriter(filename + ".out"));
tokenizer = new StringTokenizer("");
}
private static String nextLine() throws IOException {
return reader.readLine();
}
private static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(nextLine());
}
return tokenizer.nextToken();
}
private static int nextInt() throws IOException {
return Integer.parseInt(next());
}
private static long nextLong() throws IOException {
return Long.parseLong(next());
}
private static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
init(System.in, System.out);
int n = nextInt();
//long startTime = System.currentTimeMillis();
if (n > 0) {
out.write(n + "\n");
} else {
String s = n + "";
String s2 = s.substring(0, s.length() - 1);
String s3 = s.substring(0, s.length() - 2) + s.charAt(s.length() - 1);
int a = Integer.parseInt(s2);
int b = Integer.parseInt(s3);
int ans = Math.max(a, b);
out.write(ans + "\n");
}
//long runTime = System.currentTimeMillis() - startTime;
//out.write(runTime + "\n");
out.flush();
}
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.*;
public class Main {
StreamTokenizer in;
int n, k;
public void run() {
in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
read();
print(solve());
}
void read() {
n = nextInt();
// k = nextInt();
}
int solve() {
int result = n;
if (result < 0) {
int res1 = n / 10;
int mod = n % 10;
int res2 = res1 / 10 * 10 + mod;
if (res1 > res2)
result = res1;
else
result = res2;
}
return result;
}
void print(int result) {
System.out.println(result);
}
public static void main(String[] Args) {
new Main().run();
}
public int nextInt() {
try {
in.nextToken();
}
catch (Exception e) {}
return (int)in.nval;
}
public String nextString() {
try {
in.nextToken();
}
catch (Exception e) {}
return in.sval;
}
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BankAccount {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s = in.readLine();
int n = Integer.parseInt(s);
if (s.charAt(0) == '-')
if (Integer.parseInt(s.substring(0, s.length()-1))>Integer.parseInt(s.substring(0, s.length()-2)+s.charAt(s.length()-1)))
s=s.substring(0, s.length()-1);
else
s=s.substring(0, s.length()-2)+s.charAt(s.length()-1);
System.out.println(Integer.parseInt(s));
in.close();
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.*;
import java.util.*;
public class A {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
void solve() throws IOException {
String s = nextToken();
int res = Integer.parseInt(s);
String s1 = s.substring(0, s.length() - 1);
res = Math.max(res, Integer.parseInt(s1));
String s2 = s.substring(0, s.length() - 2) + s.charAt(s.length() - 1);
res = Math.max(res, Integer.parseInt(s2));
out.println(res);
}
A() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new A();
}
String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.nextToken();
}
String nextString() {
try {
return br.readLine();
} catch (IOException e) {
eof = true;
return null;
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A {
static StringTokenizer st;
static BufferedReader in;
static PrintWriter pw;
public static void main(String[] args) throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = nextInt();
int n1 = n/10;
int s = n % 10;
int n2 = n / 100 * 10+s;
System.out.println(Math.max(n, Math.max(n1, n2)));
pw.close();
}
private static int nextInt() throws IOException{
return Integer.parseInt(next());
}
private static long nextLong() throws IOException{
return Long.parseLong(next());
}
private static double nextDouble() throws IOException{
return Double.parseDouble(next());
}
private static String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class TaskA implements Runnable {
@Override
public void run() {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = in.readInt();
if (n > 0) {
out.println(n);
}
else {
int nn = -n;
int x = nn/10;
int lastDigit = nn%10;
int y = 10*(x/10) + lastDigit;
x = -x;
y = -y;
out.println(x > y ? x : y);
}
out.flush();
}
public static void main(String[] args) {
new TaskA().run();
}
private class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int readInt() {
return Integer.parseInt(next());
}
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author George Marcus
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int N = in.nextInt();
if(N >= 0)
out.println(N);
else {
N = Math.abs(N);
int v1 = - (N / 10);
int v2 = - (N / 100 * 10 + (N % 10));
out.println(Math.max(v1, v2));
}
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
return Integer.parseInt(nextString());
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class CFA {
private void work() throws IOException {
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(
System.in)));
while (sc.hasNextInt()) {
int n = sc.nextInt();
int a = n;
int b = n / 10;
int c;
if (n < 0) {
n = -n;
c = -((n / 100) * 10 + n % 10);
} else {
c = (n / 100) * 10 + n % 10;
}
System.out.println(Math.max(a, Math.max(b, c)));
}
System.out.close();
}
private int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public static void main(String[] args) throws IOException {
new CFA().work();
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.util.Scanner;
public class A {
/**
* @param args
*/
public static void main(String[] args) {
Account acnt = new Account();
acnt.solve();
acnt.print();
}
}
class Account {
Account() {
Scanner scr = new Scanner(System.in);
n = scr.nextInt();
}
void solve() {
if (n > 0) {
ans = n;
}
else {
int nn = -n;
int ans1 = nn/10;
int ans2 = nn % 10 + (nn/100)*10;
if (ans1 < ans2){
ans = -ans1;
}
else {
ans = -ans2;
}
}
}
void print(){
System.out.println(ans);
}
int ans;
int n;
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.Scanner;
public class ProblemB {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int a = s.nextInt();
int f1 = a/10;
int b = a;
int last = a%10;
b/=10;
b/=10;
b*=10;
b+=last;
System.out.println(Math.max(a, Math.max(f1, b)));
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;
/** UVA 10130 - SuperSale */
public class Main {
/** totally n products, max Weight is w */
public static void main(String[] args) throws Exception {
Scanner sc = null;
PrintWriter pr = null;
pr=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
//sc = new Scanner(new File("input.txt"));
long n = sc.nextInt();
if (n > 0) pr.println(n);
else {
long n1 = n / 10;
long n2 = n / 100 * 10 + n % 10;
if (n1 < n2) pr.println(n2);
else pr.println(n1);
}
pr.close();
sc.close();
}
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.util.*;
public class Bank{
public static void main(String[] args){
Scanner reader = new Scanner(System.in);
int in = reader.nextInt();
int sign = (int)Math.signum(in);
String str = Math.abs(in)+"";
if(str.length() == 1){
if(in < 0)
System.out.println(0);
else
System.out.println(in);
return;
}
int max = in;
max = Math.max(max, sign * Integer.parseInt(str.substring(0,str.length()-1)));
max = Math.max(max, sign * Integer.parseInt(str.substring(0,str.length()-2) + str.charAt(str.length()-1)));
System.out.println(max);
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.*;
import java.util.*;
public class first
{
int max(int a1,int a2,int a3)
{
int max=a1;
if(a2>=max)
max=a2;
if(a3>=max)
max = a3;
return max;
}
public static void main(String[] args)
{
int num=0;
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
int num2 = num/10;
int num3 = num%10;
int num4 = (num2/10)*10+num3;
first fs = new first();
int result = fs.max(num,num2,num4);
System.out.println(result);
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.InputStreamReader;
import java.io.IOException;
import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
public class palin {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(System.out);
Scanner scan = new Scanner(System.in);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
}
class TaskC {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
if (n >= 0) {
out.print(n);
return;
}
if (n / 10 >= (n / 100) * 10 + n % 10) {
out.print(n / 10);
return;
}
out.print((n / 100) * 10 + n % 10);
}
}
class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
st = null;
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
/**
*
* @author saurabh
*/
public class myTemplate {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception{
// TODO code application logic here
java.io.BufferedReader br = new java.io.BufferedReader(new
java.io.InputStreamReader(System.in));
int ch[],arr[];
int x,i,j,k,t,n=Integer.parseInt(br.readLine());
//System.out.println(n);
if(n>0)
System.out.println(n);
else
{
//n= -n;
//n=-n;
x= n/100;
x = x*10 + n%10;
// System.out.println(x);
if(n/10 > x)
System.out.println(n/10);
else
System.out.println(x);
}
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.*;
import java.util.*;
public class A {
public static void main(String[] args){
FastScanner sc = new FastScanner();
int n = sc.nextInt();
String nStr = Integer.toString(n);
String nStr1 = nStr.substring(0, nStr.length() - 1);
String nStr2 = nStr.substring(0, nStr.length() - 2) + nStr.charAt(nStr.length() - 1);
int result = Math.max(n, Integer.parseInt(nStr1));
result = Math.max(result, Integer.parseInt(nStr2));
System.out.println(result);
}
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.*;
public class Main {
public static void main(String args[]) throws IOException {
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
String line = stdin.readLine();
int n = Integer.parseInt(line);
if (n >= 0) {
System.out.println(n);
} else if (n > -10) {
System.out.println(0);
} else {
String sa = line.substring(0, line.length() - 1);
int a = Integer.parseInt(sa);
String sb = line.substring(0, line.length() - 2) + line.charAt(line.length() - 1);
int b = Integer.parseInt(sb);
System.out.println(Math.max(a, b));
}
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.PrintWriter;
import java.util.Scanner;
public class C186D2A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
if (n >= 0) {
out.println(Math.abs(n));
} else {
out.println(Math.max(n/10, (n/100)*10 + n%10));
}
out.flush();
}
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A {
private static StringTokenizer tokenizer;
private static BufferedReader bf;
private static PrintWriter out;
private static int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
@SuppressWarnings("unused")
private static long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
private static String nextToken() throws IOException {
while(tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(bf.readLine());
}
return tokenizer.nextToken();
}
public static void main(String[] args) throws IOException {
bf = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = nextInt();
if(n >= 0) out.println(n);
else {
n = -n;
int a = n % 10; int m = n/10;
int b = m % 10;
if(a >= b) {
if(m == 0) out.println(0);
else out.println(-m);
}
else {
m = (m-b)+a;
if(m == 0) out.println(0);
else out.println(-m);
}
}
out.close();
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class A {
private static BufferedReader in;
private static StringTokenizer st;
private static PrintWriter out;
public static void main(String[] args) throws NumberFormatException, IOException {
in = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = nextInt();
int max = n;
max = Math.max(max, n / 10);
max = Math.max(max, (n / 100) * 10 + n % 10);
System.out.println(max);
}
static String next() throws IOException{
while(!st.hasMoreTokens()){
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
static int nextInt() throws NumberFormatException, IOException{
return Integer.parseInt(next());
}
static long nextLong() throws NumberFormatException, IOException{
return Long.parseLong(next());
}
static double nextDouble() throws NumberFormatException, IOException{
return Double.parseDouble(next());
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class problemB185 {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb=new StringBuffer();
int n=Integer.parseInt(br.readLine());
if(n<0){
int temp=-n;
int temp2=temp/10;
int x=temp%10;
int y=temp2%10;
if(x>y){
temp=temp/10;
}
else{
temp=temp/10 -y +x;
}
n=-temp;
}
System.out.println(n);
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws NumberFormatException,
IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String s = n + "";
if (n >= 0)
System.out.println(n);
else {
int a = n, b = Integer.parseInt(s.substring(0, s.length() - 1)), c = Integer.parseInt(s.substring(0, s.length()-2)+s.charAt(s.length()-1));
System.out.println(Math.max(a, Math.max(b,c)));
}
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.util.Scanner;
public class A {
static Scanner scanner = new Scanner(System.in);
static int s;
public static void main(String[] args) {
s = scanner.nextInt();
if (s >= 0) {
System.out.println(s);
}
else {
if (s >= -10) {
System.out.println(0);
}
else {
int ss = -s;
int a, b;
a = ss % 10;
b = (ss % 100) / 10;
if (a > b) {
ss = ss / 10;
}
else {
ss = (ss / 100) * 10 + a;
}
if (ss == 0) {
System.out.println(0);
}
else {
System.out.println("-" + ss);
}
}
}
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.*;
import static java.lang.Integer.*;
import static java.lang.Math.*;
public class A {
public static void main(String[] args) throws Throwable{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String ln=in.readLine().trim();
System.out.println(max(parseInt(ln),max(parseInt(ln.substring(0,ln.length()-1)),parseInt(ln.substring(0, ln.length()-2)+ln.substring(ln.length()-1)))));
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedInputStream;
import java.io.PrintStream;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(new BufferedInputStream(System.in));
PrintStream out=System.out;
int n=in.nextInt();
if (n>=0) out.println(n);
else out.println(Math.max(-((-n)/10), -((-n)/100*10+(-n)%10)));
out.close();
in.close();
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String [] args ) {
try{
String str;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedOutputStream bos = new BufferedOutputStream(System.out);
String eol = System.getProperty("line.separator");
byte [] eolb = eol.getBytes();
byte[] spaceb= " ".getBytes();
str = br.readLine();
int n = Integer.parseInt(str);
int ans = 0;
if(n>=0) {
ans = n;
} else {
if ( str.length()==2) {
if(str.charAt(0)!='-') {
int a =Integer.parseInt(str.substring(0,1));
int b = Integer.parseInt(str.substring(1,2));
ans = Math.max(a, b);
} else {
ans = Integer.parseInt(str.substring(1,2));
}
} else {
String s1 = str.substring(0,str.length()-2).concat(str.substring(str.length()-2,str.length()-1));
String s2 = str.substring(0,str.length()-2).concat(str.substring(str.length()-1,str.length()));
int a = Integer.parseInt(s1);
int b = Integer.parseInt(s2);
ans = Math.max(a, b);
}
}
bos.write(new Integer(ans).toString().getBytes());
bos.write(eolb);
bos.flush();
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.util.*;
public class Main{
void solve(){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int n1 = n/10;
int n2 = n/100*10 + n%10;
int ans = n;
ans = Math.max(ans, n1);
ans = Math.max(ans, n2);
System.out.println(ans);
}
public static void main(String[] args){
new Main().solve();
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.*;
import java.util.*;
import java.math.*;
public class A {
public static void main(String[] args) {
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
Application solver = new Application();
solver.solve(System.in, out);
out.close();
}
}
class Application {
int max(int a, int b) { return a > b ? a : b; }
public void solve(InputStream in, PrintWriter out) {
Scanner scanner = new Scanner(in);
int n = scanner.nextInt();
int n1 = n/10;
int n2 = (n/100)*10+(n%10);
int m = max(max(n1, n2), n);
out.println(m);
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import static java.util.Arrays.deepToString;
import java.awt.datatransfer.StringSelection;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class Main {
static void solve() throws IOException {
int n = nextInt();
if (n >= 0) {
System.out.println(n);
} else {
String string = String.valueOf(n);
int v1 = Integer.valueOf(string.substring(0, string.length() - 1));
int v2 = Integer.valueOf(string.substring(0, string.length() - 2)
+ string.charAt(string.length() - 1));
if (v1 >= v2) {
System.out.println(v1);
} else {
System.out.println(v2);
}
}
}
public static void main(String[] args) throws Exception {
reader = new BufferedReader(new InputStreamReader(System.in));
writer = new PrintWriter(System.out);
setTime();
solve();
printTime();
printMemory();
writer.close();
}
static BufferedReader reader;
static PrintWriter writer;
static StringTokenizer tok = new StringTokenizer("");
static long systemTime;
static void debug(Object... o) {
System.err.println(deepToString(o));
}
static void setTime() {
systemTime = System.currentTimeMillis();
}
static void printTime() {
System.err.println("Time consumed: "
+ (System.currentTimeMillis() - systemTime));
}
static void printMemory() {
System.err.println("Memory consumed: "
+ (Runtime.getRuntime().totalMemory() - Runtime.getRuntime()
.freeMemory()) / 1000 + "kb");
}
static String next() {
while (!tok.hasMoreTokens()) {
String w = null;
try {
w = reader.readLine();
} catch (Exception e) {
e.printStackTrace();
}
if (w == null)
return null;
tok = new StringTokenizer(w);
}
return tok.nextToken();
}
static int nextInt() {
return Integer.parseInt(next());
}
static long nextLong() {
return Long.parseLong(next());
}
static double nextDouble() {
return Double.parseDouble(next());
}
static BigInteger nextBigInteger() {
return new BigInteger(next());
}
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int balance = in.nextInt();
if (balance >= 0) {
out.println(balance);
return;
}
balance = -balance;
int a = balance / 100;
int b = Math.min(balance % 10, (balance / 10) % 10);
balance = -(a * 10 + b);
out.println(balance);
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.*;
import java.util.*;
public class Problem1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if (n < 0) {
int first = n / 10;
int second = (n / 100)*10 + (n % 10);
if (first > second)
System.out.println(first);
else
System.out.println(second);
} else {
System.out.println(n);
}
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.*;
import java.util.*;
public class j
{
public static void main(String aa[])throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int i=0,m=0,p=0,n=0,k=0,j=0;
String s,r;
s=b.readLine();
r=s;
n=Integer.parseInt(s);
s=s.substring(0,s.length()-2);
s+=r.charAt(r.length()-1);
r=r.substring(0,r.length()-1);
m=Integer.parseInt(s);
p=Integer.parseInt(r);
System.out.print((long)Math.max(Math.max(m,n),p));
}
} | constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A {
public static void main(String[] args){
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
String cur = sc.nextToken();
int first = Integer.parseInt(cur);
if(cur.length() > 1){
String second = cur.substring(0,cur.length()-1);
if(Character.isDigit(second.charAt(second.length()-1))){
first = Math.max(first, Integer.parseInt(second));
}
}
if(cur.length() > 2){
String third = cur.substring(0,cur.length()-2) + cur.charAt(cur.length()-1);
if(Character.isDigit(cur.charAt(cur.length()-2))){
first = Math.max(first, Integer.parseInt(third));
}
}
System.out.println(first);
out.close();
}
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.io.*;
import java.math.*;
import java.util.*;
@SuppressWarnings("unused")
public class A {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
TreeSet<Integer> set = new TreeSet<Integer>();
set.add(n);
try {
String s = Integer.toString(n);
s = s.substring(0, s.length() - 1);
set.add(Integer.parseInt(s));
} catch (Exception e) {
}
try {
String s = Integer.toString(n);
s = s.substring(0, s.length() - 2) + s.charAt(s.length() - 1);
set.add(Integer.parseInt(s));
} catch (Exception e) {
}
System.out.println(max(set));
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Round313A {
private static final int LOCAL_ENV = 0;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
try {
if (LOCAL_ENV == 1) {
in = new Scanner(new File("input.txt"));
}
} catch (FileNotFoundException e) {
in = new Scanner(System.in);
}
long n = in.nextLong();
if (n >= -9) {
System.out.println(n);
} else {
long absN = Math.abs(n);
long m1 = -(absN / 10);
long last = absN % 10;
long m2 = -((absN / 100) * 10 + last);
System.out.println(Math.max(m1, m2));
}
}
}
| constant | 313_A. Ilya and Bank Account | CODEFORCES |