| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
竟然M_PI编译不过?坑!我include了math.h和cmath都不行,什么鬼玩意啊!为此贡献了两次CE。。。
//============================================================================
// Name : main2007.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cmath>
using namespace std;
const double M_PI_ = 3.141592654;
double jiao(int x, int y){
if(y == 0 && x > 0) return 0;
if(y == 0 && x < 0) return M_PI_;
double ac = acos(x/sqrt(x*x+y*y+0.0));
//cout << ac << endl;
double res = ac * 180 / M_PI_;
if(y > 0) return res;
return 360 - res;
}
int partion(double *array, int *xes, int *yes, int p, int r) {
double x = array[r];
int i = p - 1;//注意这点,把i设成负值,然后作为移动的标志
int j;
for (j = p; j < r; j++) {
if (array[j] < x) {
i++;
double temp = array[j];
array[j] = array[i];
array[i] = temp;
int tmp = xes[j];
xes[j] = xes[i];
xes[i] = tmp;
tmp = yes[j];
yes[j] = yes[i];
yes[i] = tmp;
}
}
double temp = array[j];
array[j] = array[i + 1];
array[i + 1] = temp;
int tmp = xes[j];
xes[j] = xes[i+1];
xes[i+1] = tmp;
tmp = yes[j];
yes[j] = yes[i+1];
yes[i+1] = tmp;
return i+1;//返回的应该是交换后的哨兵的位置
}
//递归解决每个划分后的小
void quickSort(double *array, int *xes, int *yes, int p, int r) {
if (p < r) {
int q = partion(array, xes, yes, p, r);
quickSort(array, xes, yes, p, q - 1);
quickSort(array, xes, yes, q + 1, r);
}
}
int main() {
//cout << M_PI << endl;
int zero_x, zero_y;
int x_temp, y_temp;
int xes[110], yes[110];
double jes[110];
int cnt = 0;
cin >> zero_x >> zero_y;
if(zero_x != 0 || zero_y != 0) return -1;
while(cin >> x_temp >> y_temp){
if(x_temp == 0 && y_temp == 0) break;
xes[cnt] = x_temp;
yes[cnt] = y_temp;
cnt++;
}
//cout << cnt << endl;
for(int i = 0; i < cnt; i++){
jes[i] = jiao(xes[i], yes[i]);
}
quickSort(jes, xes, yes, 0, cnt-1);
///for(int i = 0; i < cnt; i++){
// cout << xes[i] << " " << yes[i] << " " << jes[i] << endl;
//}
jes[cnt] = jes[0] + 360;
cout << "(0,0)" << endl;
int start = 0;
for(int i = 0; i < cnt; i++){
if(jes[i+1] - jes[i] > 180){
start = i+1;
break;
}
}
for(int i = start; i < start+cnt; i++){
cout << "(" << xes[i%cnt] << "," << yes[i%cnt] << ")" << endl;
}
//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator