UVa 12004 Bubble Sort: Idea questions

Source: Internet
Author: User
Tags cas printf sort

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= 3155

Enumeration Exchange count is too troublesome, may wish to change the idea: for any pair of numbers, the probability of exchange between them and the probability of not exchanging is equal, that the expected value of the number is 1/2. There is a total of C (n,2) on the number, so the ultimate expectation is n (n-1)/4

Complete code:

01./*0.015s*/
.  
#include <cstdio>  
.  
05.int Main ()  
06.{    long x;  
"    int T", cas = 0;    scanf ("%d", &t);  
While    (t--)  
.    {        scanf ("%lld", &x);  
x        = x * (x-1) >> 1;        printf ("Case%d:", ++cas);        if (x & 1) printf ("%lld/2\n", x);        Else printf ("%lld\n", x >> 1);  
18.}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.