Skip to main content

Posts

Showing posts from March, 2017

UVA 10812(Beat the Spread)

Superbowl Sunday is nearly here. In order to pass the time waiting for the half-time commercials and wardrobe malfunctions, the local hackers have organized a betting pool on the game. Members place their bets on the sum of the two final scores, or on the absolute difference between the two scores. Given the winning numbers for each type of bet, can you deduce the final scores? Input The first line of input contains n, the number of test cases. n lines follow, each representing a test case. Each test case gives s and d, non-negative integers representing the sum and (absolute) difference between the two final scores. Output For each test case, output a line giving the two final scores, largest first. If there are no such scores, output a line containing “impossible”. Recall that football scores are always non-negative integers. Sample Input 2 40 20 20 40 Sample Output 30 10  impossible #include<iostream> #include<cstdio> #include<math.h> #include...

UVA 10235 (reverse prime)

solution : #include<stdio.h> #include<math.h> int  long is_prime(int long n); int long  reverse (int  long n); int main() {       int long  n,rev=0,tmp=0;       while(scanf("%ld",&n)==1){       if(n==is_prime(n)){             tmp=reverse(n);             if(tmp==is_prime(tmp)){                   if(tmp==n)                   printf("%ld is prime.\n",n);                   else                   printf("%ld is emirp.\n",n);             }                   else                   printf("%ld is prime.\n",n);       }  ...

codeforce problemset 758A solved

A. Holiday Of Equality time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are  n  citizens, the welfare of each of them is estimated as the integer in  a i  burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. Input The first line contains the integer  n  ( 1 ≤  n  ≤ 100 ) — the number of citizens in the kingdom. The second line contains  n  integers  a 1 ,  a 2 , ...,  a n , where  a i  ( 0 ≤  a i  ≤ 10 6 ) — the welfare of the  i -th citizen. Output In the only li...

Timus 1068

1068. Sum Time limit: 2.0 second Memory limit: 64 MB Your task is to find the sum of all integer numbers lying between 1 and  N  inclusive. Input The input consists of a single integer  N  that is not greater than 10000 by it's absolute value. Output Write a single integer number that is the sum of all integer numbers lying between 1 and  N  inclusive. Sample input output -3 -5 Problem Source:  2000-2001 ACM Northeastern European Regional Programming Contest (test tour) #include<iostream> #include<cstdio> #include<cmath> using namespace std; int main() {     int n, sum;     scanf("%d", &n);     sum = 0;     if(n>0)     {         sum = (n*(n+1))/2;     }     else if(n<=0)     {         sum = ((n*(n-1))/2)*(-1);         ...