ZOJ 1730 Crazy Tea Party

Source: Internet
Author: User

ZOJ 1730 Crazy Tea Party (5418)

Test instructions: People sit around the round table and ask how many times they need to exchange a group of people at least to get everyone in the opposite order.

Idea: One pair means and can only be exchanged for two people next to each other. Bubble sort. But 1 2 3 4 5 does not need to become 5 4 3 2 1, 5 to 1 after the back, into 2 1 5 4 3, is the minimum number of times. The number of people is odd and even two cases, the number of exchanges formula X = N (n-1)/2;.

Code:

#include <stdio.h>
int main () {
	int n,i,x,a,t;
	scanf ("%d", &n);
	for (i = 1;i<=n;i++) {
		scanf ("%d", &x);
		if (x%2==0) {
			t = X/2;
			A = t* (t-1);
			printf ("%d\n", a);
			Continue;
		}
		if (x%2==1) {
			t = (x+1)/2;
			A = t* (t-1)/2+ (t-1) * (t-2)/2;
			printf ("%d\n", a);
			Continue;
		}
	}
	return 0;
}


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.