# Monthly Archives: May 2014

## Poj Solution 2766

http://poj.org/problem?id=2766 /* @author: */ import java.util.Scanner; import java.util.Arrays; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int dx[]={0,1,0,-1},dy[]={1,0,-1,0}; int g[][]=new int[52][52]; int ca,i,j,k,n,r,x,y,dir; ca=sc.nextInt(); while ((ca–)!=0) { n=sc.nextInt(); r=sc.nextInt(); for(i=0;i< g.length;i++) Arrays.fill(g[i],0); for … Continue reading

## Poj Solution 2765

http://poj.org/problem?id=2765 #include <stdio.h> #include <string.h> struct product{ char w[100]; char name[110][100]; int per[110]; int most[110], least[110]; int m; }p[10]; int n; void clac( product &a ) { int s = 0, r = 100, i, j, k, low[100], up[100], sum, … Continue reading

## Poj Solution 2760

http://poj.org/problem?id=2760 #include "stdio.h" #include "math.h" #include "memory.h" #include "algorithm" using namespace std; #define y1 sdgdsf double clac( double h0, double h1, double x0, double x1 ) { return h0/(h0-h1)*( x1 – x0 ) + x0; } double sum[5048]; struct node … Continue reading

## Poj Solution 2757

http://poj.org/problem?id=2757 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String args[]) throws Exception { Scanner cin=new Scanner(System.in); BigInteger n; long b; while(cin.hasNext()) { n=cin.nextBigInteger(); b=cin.nextLong(); if(n.compareTo(BigInteger.ZERO)<=0) { System.out.println("0"); continue; } BigInteger ans; … Continue reading

## Poj Solution 2756

http://poj.org/problem?id=2756 import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int num = Integer.valueOf(cin.nextLine()).intValue(); for(int i = 0; i < num; i++) { String[] str = cin.nextLine().split(" "); BigDecimal a … Continue reading

## Poj Solution 2751

http://poj.org/problem?id=2751 /* @author: */ import java.util.Scanner; public class Main { static int a[][]=new int[10001][2]; static int b[][]=new int[10001][2]; static int an,bn; static void sort(){ int i,j,t1,t2; for(i=0;i< an;i++) for(j=0;j< an;j++) { if(a[i][0]< a[j][0]) { t1=a[i][0];t2=a[i][1]; a[i][0]=a[j][0];a[i][1]=a[j][1]; a[j][0]=t1;a[j][1]=t2; } } for(i=0;i< … Continue reading

## Poj Solution 2750

http://poj.org/problem?id=2750 #include "stdio.h" #include "memory.h" const int SIZE = ( 1<<18 ); const int LEAF = ( 1<<17) – 1; int sum[SIZE],l_max[SIZE],r_max[SIZE],l_min[SIZE], r_min[SIZE], min_e[SIZE], s_max[SIZE], s_min[SIZE], pn, n; inline int max( int a, int b ) { return a>b?a:b; } … Continue reading

## Poj Solution 2749

http://poj.org/problem?id=2749 #include "stdio.h" #include "memory.h" #include "vector" #include "algorithm" #include "functional" #include "math.h" #define max asdfds using namespace std; const int SIZE = 700; typedef pair<int,int> pair_int; int sign[SIZE*2], MS; pair_int e[SIZE*2][SIZE*2], _e[SIZE*2][SIZE*2]; int en[SIZE*2], _en[SIZE*2]; int n; void init( … Continue reading

## Poj Solution 2748

http://poj.org/problem?id=2748 import java.io.*; class Main { public static void main(String[] args) throws IOException { InputStreamReader is=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(is); int a=Integer.parseInt(in.readLine()); int[] fb=new int[75000]; fb[0]=1; fb[1]=1; for(int i=2;i< 75000;i++) fb[i]=(3*fb[i-1]-fb[i-2]+200000)%100000; while((a–)!=0) { int b=Integer.parseInt(in.readLine()); System.out.println(fb[b%75000]); } } }

## Poj Solution 2744

http://poj.org/problem?id=2744 /* @author: */ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double b,v,e,f,t[]=new double[101],t1; int n,a[]=new int[101],r; int i,j,k,dis; while(sc.hasNext()) { n=sc.nextInt(); if(n==0) break; a[0]=0; for(i=1;i<=n;i++) a[i]=sc.nextInt(); b=sc.nextDouble(); r=sc.nextInt(); v=sc.nextDouble(); … Continue reading

## Poj Solution 2739

http://poj.org/problem?id=2739 import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=1; while(true){ n=sc.nextInt(); if(n==0) break; System.out.println(test2(n)); } } /* * Sum of Consecutive Prime Numbers */ public static int test2(int x){ int count=0; for(int i=2;i+i< … Continue reading

## Poj Solution 2738

http://poj.org/problem?id=2738 //* @author: ccQ.SuperSupper import java.io.*; import java.util.*; public class Main { static final int M = 2,N = 1000+2; static int value[] = new int[N]; static int map[][][] = new int[N][N][M],n; public static int Get_Num(StreamTokenizer cin) throws Exception{ cin.nextToken(); … Continue reading

## Poj Solution 2728

http://poj.org/problem?id=2728 //* @author: import java.util.*; import java.math.*; import java.io.FileReader; class Node{ int x,y,z; } public class Main { static int []mark=new int[1010]; static double []dis=new double[1010]; static int []from=new int [1010]; static double sumup,sumdown; static double [][]up=new double [1010][1010]; static … Continue reading