您的位置:首页 > 其它

zoj 1730 || poj 1455 Crazy Tea Party(= =)

2010-11-07 13:48 459 查看
开始不会写,看人家思路了 = = YM.。



按照冒泡排序的思想,时间为n*(n-1)/2



因为是个环,可以将n分成两部分进行排序。



然后将时间累加即可 = =。。。。啊呀呀。。



#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
using namespace std;
int main(void)
{
	int ncases,n,times;
	cin >> ncases;
	while( ncases-- )
	{
		cin >> n;
		times = n/2*(n/2-1)/2+(n-n/2)*(n-n/2-1)/2;
		cout << times;
		if( ncases )	
			cout << endl;
	}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: