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

开始不会写,看人家思路了 = = 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; }  

你可能感兴趣的:(zoj 1730 || poj 1455 Crazy Tea Party(= =))