鱼C论坛

 找回密码
 立即注册
查看: 2322|回复: 0

新人求助poj1328!望好心人帮忙解决,万分感谢!

[复制链接]
发表于 2014-7-25 08:48:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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]
  1. #include<iostream>
  2. #include<vector>
  3. #include<cmath>
  4. using namespace std;

  5. struct island{
  6.         double x;
  7.         double y;
  8.         double distance;
  9.         double t =  pow((distance * distance - y * y),0.5);
  10.         
  11.         double start = ceil(x - t);
  12.         double end = floor(x + t);
  13. };

  14. void sort(double *start,int landNum)//用雷达区间起始点排序岛屿
  15. {
  16.         for(int i = landNum - 1;i > 0;i--)
  17.         {
  18.                 if(start[i] < start[i - 1])
  19.                 {
  20.                         double temp = start[i - 1];
  21.                         start[i - 1] = start[i];
  22.                         start[i] = temp;
  23.                 }
  24.         }
  25. }


  26. //size是已经存入容器中岛屿个数
  27. //a[]是已经存入岛屿的结束点
  28. //start是当前岛屿起始点


  29. int test(int size ,double* a,double start)
  30. {
  31.         int flag = 1;
  32.         for(int i = 0;i < size;i++)
  33.         {
  34.                 if(start <= a[i])
  35.                         flag = 0;
  36.         }        
  37.         return flag;
  38. }




  39. int main()
  40. {
  41.         //input
  42.         int islandNum;
  43.         double radarDistance;
  44.         int d = 1;
  45.         while (cin >> islandNum >> radarDistance&&(islandNum || radarDistance))
  46.         {
  47.                 island island[islandNum];
  48.                 for(int i = 0;i < islandNum;i++)
  49.                 {
  50.                         cin >> island[i].x >> island[i].y;
  51.                         island[i].distance = radarDistance;
  52.                 }
  53.                
  54.                 double start1[islandNum];//存储所有岛屿的雷达区间起始点
  55.                 for(int i = 0;i < islandNum;i++)
  56.                 {
  57.                         start1[i] = island[i].start;
  58.                 }
  59.                 sort(start1,islandNum);
  60.                
  61.                 vector<int> islandSubcript;//存储被选中雷达的岛屿下标
  62.                 islandSubcript.push_back(0);//第一个岛屿必然被选中
  63.                
  64.                 for(int i = 1;i < islandNum;i++)
  65.                 {
  66.                         //比较当前第i+1岛屿与之前所有岛屿的结束点,若符合加入容器
  67.                         double a[islandSubcript.size()];//存储所有岛屿结束点
  68.                         for(int j = 0;j < islandSubcript.size();j++)
  69.                         {
  70.                                 a[j] = island[j].end;
  71.                         }
  72.                         
  73.                         double s = island[i].start;
  74.                         if(test(islandSubcript.size(),a,s))
  75.                         {
  76.                                 islandSubcript.push_back(i);
  77.                         }
  78.                 }
  79.                 cout << "Case " << d++<<": " <<islandSubcript.size()<<endl;
  80.         }
  81.         
  82. return 0;
  83. }
复制代码







小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-10 14:59

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表