|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 勿语静候 于 2014-7-25 09:21 编辑
下面是poj1328代码,自己在DEV c++上编译通过,运行正确。为什么在poj上编译错误。这是poj给出的错误Main.cppF:\temp\13162134.571\Main.cpp(10) : error C2327: 'island::distance' : is not a type name, static, or enumerator
F:\temp\13162134.571\Main.cpp(10) : error C2327: 'island::distance' : is not a type name, static, or enumerator
F:\temp\13162134.571\Main.cpp(10) : error C2563: mismatch in formal parameter list
F:\temp\13162134.571\Main.cpp(10) : error C2568: '*' : unable to resolve function overload xutility(1855): could be 'iterator_traits<_Iter>::difference_type std::distance(_InIt,_InIt)'
F:\temp\13162134.571\Main.cpp(10) : error C2327: 'island::y' : is not a type name, static, or enumerator
F:\temp\13162134.571\Main.cpp(10) : error C2065: 'y' : undeclared identifier
F:\temp\13162134.571\Main.cpp(10) : error C2327: 'island::y' : is not a type name, static, or enumerator
F:\temp\13162134.571\Main.cpp(10) : error C2065: 'y' : undeclared identifierF:\temp\13162134.571\Main.cpp(10) : error C2864: 'island::t' : only static const integral data members can be initialized within a class
F:\temp\13162134.571\Main.cpp(12) : error C2327: 'island::x' : is not a type name, static, or enumerator
F:\temp\13162134.571\Main.cpp(12) : error C2065: 'x' : undeclared identifier
F:\temp\13162134.571\Main.cpp(12) : error C2327: 'island::t' : is not a type name, static, or enumerator
F:\temp\13162134.571\Main.cpp(12) : error C2065: 't' : undeclared identifier
F:\temp\13162134.571\Main.cpp(12) : error C2864: 'island::start' : only static const integral data members can be initialized within a class
F:\temp\13162134.571\Main.cpp(13) : error C2327: 'island::x' : is not a type name, static, or enumerator
F:\temp\13162134.571\Main.cpp(13) : error C2065: 'x' : undeclared identifier
F:\temp\13162134.571\Main.cpp(13) : error C2327: 'island::t' : is not a type name, static, or enumerator
F:\temp\13162134.571\Main.cpp(13) : error C2065: 't' : undeclared identifier
F:\temp\13162134.571\Main.cpp(13) : error C2864: 'island::end' : only static const integral data members can be initialized within a class
F:\temp\13162134.571\Main.cpp(57) : error C2057: expected constant expression
F:\temp\13162134.571\Main.cpp(57) : error C2466: cannot allocate an array of constant size 0
F:\temp\13162134.571\Main.cpp(57) : error C2133: 'island' : unknown size
F:\temp\13162134.571\Main.cpp(64) : error C2057: expected constant expression
F:\temp\13162134.571\Main.cpp(64) : error C2466: cannot allocate an array of constant size 0
F:\temp\13162134.571\Main.cpp(64) : error C2133: 'start1' : unknown size
F:\temp\13162134.571\Main.cpp(77) : error C2057: expected constant expression
F:\temp\13162134.571\Main.cpp(77) : error C2466: cannot allocate an array of constant size 0
F:\temp\13162134.571\Main.cpp(77) : error C2133: 'a' : unknown size这是自己电脑给出的 warning[Warning] non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]- #include<iostream>
- #include<vector>
- #include<cmath>
- using namespace std;
- struct island{
- double x;
- double y;
- double distance;
- double t = pow((distance * distance - y * y),0.5);
-
- double start = ceil(x - t);
- double end = floor(x + t);
- };
- void sort(double *start,int landNum)//用雷达区间起始点排序岛屿
- {
- for(int i = landNum - 1;i > 0;i--)
- {
- if(start[i] < start[i - 1])
- {
- double temp = start[i - 1];
- start[i - 1] = start[i];
- start[i] = temp;
- }
- }
- }
- //size是已经存入容器中岛屿个数
- //a[]是已经存入岛屿的结束点
- //start是当前岛屿起始点
- int test(int size ,double* a,double start)
- {
- int flag = 1;
- for(int i = 0;i < size;i++)
- {
- if(start <= a[i])
- flag = 0;
- }
- return flag;
- }
- int main()
- {
- //input
- int islandNum;
- double radarDistance;
- int d = 1;
- while (cin >> islandNum >> radarDistance&&(islandNum || radarDistance))
- {
- island island[islandNum];
- for(int i = 0;i < islandNum;i++)
- {
- cin >> island[i].x >> island[i].y;
- island[i].distance = radarDistance;
- }
-
- double start1[islandNum];//存储所有岛屿的雷达区间起始点
- for(int i = 0;i < islandNum;i++)
- {
- start1[i] = island[i].start;
- }
- sort(start1,islandNum);
-
- vector<int> islandSubcript;//存储被选中雷达的岛屿下标
- islandSubcript.push_back(0);//第一个岛屿必然被选中
-
- for(int i = 1;i < islandNum;i++)
- {
- //比较当前第i+1岛屿与之前所有岛屿的结束点,若符合加入容器
- double a[islandSubcript.size()];//存储所有岛屿结束点
- for(int j = 0;j < islandSubcript.size();j++)
- {
- a[j] = island[j].end;
- }
-
- double s = island[i].start;
- if(test(islandSubcript.size(),a,s))
- {
- islandSubcript.push_back(i);
- }
- }
- cout << "Case " << d++<<": " <<islandSubcript.size()<<endl;
- }
-
- return 0;
- }
复制代码
|
|