12004 - Bubble Sort

All about problems in Volume 120. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

12004 - Bubble Sort

Post by brianfry713 » Fri Feb 01, 2013 9:54 am

Input:

Code: Select all

5
103
992
1042
555
1234
AC output:

Code: Select all

Case 1: 5253/2
Case 2: 245768
Case 3: 542361/2
Case 4: 153735/2
Case 5: 760761/2
Check input and AC output for thousands of problems on uDebug!

dibery
Learning poster
Posts: 76
Joined: Sat Feb 23, 2013 4:16 pm
Location: Taiwan, Taipei
Contact:

Re: 12004 - Bubble Sort

Post by dibery » Sun Jul 07, 2013 7:30 pm

Input:

Code: Select all

10
10000
20000
30000
40000
50000
60000
70000
80000
90000
100000
Output:

Code: Select all

Case 1: 24997500
Case 2: 99995000
Case 3: 224992500
Case 4: 399990000
Case 5: 624987500
Case 6: 899985000
Case 7: 1224982500
Case 8: 1599980000
Case 9: 2024977500
Case 10: 2499975000
[/size]
Life shouldn't be null.

sadmansobhan
New poster
Posts: 16
Joined: Thu Oct 10, 2013 8:06 am

Re: 12004 - Bubble Sort

Post by sadmansobhan » Tue Nov 05, 2013 9:20 pm

Code: Select all

#include <iostream>
#include <cstdio>

using namespace std;

long long int num;
int main()
{
    long long int test;
    cin >> test;
    for(int i=1;i<=test;i++)
    {
        cin >> num;
        if(num%4==0)
        {
            num=(num*(num-1))/4;
            cout << "Case "<< i <<": "<<num << endl;
        }
        else
        {
            num=(num*(num-1))/2;
            cout << "Case "<< i <<": "<< num << "/" << "2"<<endl;
        }
    }
    return 0;
}
getting WA though my code satisfies all sample I/O.Please help.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12004 - Bubble Sort

Post by brianfry713 » Wed Nov 06, 2013 10:02 pm

Doesn't match the sample I/O.
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12004 - Bubble Sort

Post by brianfry713 » Tue Jan 06, 2015 11:41 pm

Code: Select all

a = 1 2 3 4, findSwaps = 0
a = 1 2 4 3, findSwaps = 1
a = 1 3 2 4, findSwaps = 1
a = 1 3 4 2, findSwaps = 2
a = 1 4 2 3, findSwaps = 2
a = 1 4 3 2, findSwaps = 3
a = 2 1 3 4, findSwaps = 1
a = 2 1 4 3, findSwaps = 2
a = 2 3 1 4, findSwaps = 2
a = 2 3 4 1, findSwaps = 3
a = 2 4 1 3, findSwaps = 3
a = 2 4 3 1, findSwaps = 4
a = 3 1 2 4, findSwaps = 2
a = 3 1 4 2, findSwaps = 3
a = 3 2 1 4, findSwaps = 3
a = 3 2 4 1, findSwaps = 4
a = 3 4 1 2, findSwaps = 4
a = 3 4 2 1, findSwaps = 5
a = 4 1 2 3, findSwaps = 3
a = 4 1 3 2, findSwaps = 4
a = 4 2 1 3, findSwaps = 4
a = 4 2 3 1, findSwaps = 5
a = 4 3 1 2, findSwaps = 5
a = 4 3 2 1, findSwaps = 6
n = 4, total Swaps = 72, permutations = 24
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 120 (12000-12099)”