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

Discussion of Problem 1000. A+B Problem

aa
Posted by Proba 30 Oct 2010 17:49
this problem is so simple.
just read a and b then output a + b

Edited by author 30.10.2010 18:30
Re: aa
Posted by Igor9669 30 Oct 2010 18:14
Послано Proba 30 октября 2010 17:49

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;


public class H {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new File("horrible.in"));
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("horrible.out")));
int n = sc.nextInt();
int count = 0;
if (n == 1) {
pw.println(1);
pw.println(1 + " " + 0);
pw.close();
return;
}
count = 2;
int[][] a = new int[100000][2];
a[0][0] = 2; a[0][1] = -1;
a[1][0] = 1; a[1][1] = 0;
int bil = 1;
int tek = 2;
int nbil = 2;
int ntek = 1;
int state = 1;
one: while(true) {
switch (state) {
case 1:
if (tek <= n) {
a[count][0] = tek; a[count][1] = bil;
count++;
// System.out.println(tek + " " + bil);
tek++;
if (tek == bil) {
tek++;
}
state = -1;
} else {
a[count][0] = ++bil; a[count][1] = 0;
count++;
// System.out.println((++bil) + " " + 0);
tek = 1;
nbil++;
ntek = 1;
state = 1;
if (bil >= n) {
break one;
}
}
break;
case -1:
if (ntek <= n) {
a[count][0] = ntek; a[count][1] = 0 - nbil;
count++;
// System.out.println(ntek + " -" + nbil);
ntek++;
if (ntek == nbil) {
ntek++;
}
state = 1;
} else {
a[count][0] = ++nbil; a[count][1] = 0;
count++;
// System.out.println((++nbil) + " " + 0);
ntek = 1;
tek = 1;
state = 1;
if (nbil >= n) {
break one;
}
}
break;
default:
break;
}

}
a[count][0] = 1; a[count][1] = n;
count++;
pw.println(count);
for (int i = 0; i < count; i++) {
pw.println(a[i][0] + " " + a[i][1]);
}
pw.close();
}

}
Re: aa
Posted by holtaf 15 Nov 2010 20:22
:D