这题出得真的没问题吗?

P1086 [NOIP2004 普及组] 花生采摘

请不要质疑一道有17.35k通过的题
by 123456zmy @ 2020-02-07 22:18:09


在?宁就是语文王子?
by Alex_Wei @ 2020-02-07 22:20:40


在?宁就是语文王子?
by LTb_ @ 2020-02-07 22:41:21


您的例子是哪来的?为什么会有过程?能不能发给我看看?(也许是您坐标看反了?)
by qjyzLfy @ 2020-02-07 22:46:06


@[nangongmazha](/user/242579)
by qjyzLfy @ 2020-02-07 22:46:24


@[123456zmy](/user/44840) 我没通过,看了别人过的答案,知道原因在哪里,所以才提的疑问
by nangongmazha @ 2020-02-07 22:57:32


@[qjyzLfy](/user/207424) 是我自己只得了70分,看别人的满分题解以后的疑问。 ```cpp struct Filed { int x; int y; int count; }//结构体,定义x,y坐标和数量 int minPath(Filed start, Filed end) //计算两个坑之间的最短距离 { // int nPath1 = start.x + end.x;//出去再回来 if(start.x==0 && start.y==0)//注释掉上一句以后,为第一个坑特别处理的代码,否则不需要特别处理。 { return end.x; } int nPath2 = abs(start.x-end.x) + abs(start.y-end.y);//在田里移动 // return min(nPath1, nPath2); 原来我是考虑在田地里移动,和出去以后再回来的最小值,才是最短距离 return nPath2; //现在抛弃掉 } ```
by nangongmazha @ 2020-02-07 23:03:22


@[qjyzLfy](/user/207424) 下面是我修改以后通过的代码,但是我还是觉得题目有问题。。。。见minPath函数里的注释,求两个坑之间的最短时间 ```cpp #include <iostream> #include <math.h> #define MAXN 500 using namespace std; struct Filed { int x; int y; int count; }filed[MAXN]; int minPath(Filed start, Filed end) //计算两个坑之间的最短距离 { // int nPath1 = start.x + end.x;//出去再回来 if(start.x==0 && start.y==0)//这是注释掉上一行后不得不为第一个坑特别写的代码。 { return end.x; } int nPath2 = abs(start.x-end.x) + abs(start.y-end.y);//在田里移动 // return min(nPath1, nPath2); //原来是取田地里移动和出去再回来的最小值,现在不行了。 return nPath2; } int main() { int m, n, k, nIndex=1; int ans=0; cin>>m>>n>>k; filed[0].x = filed[0].y = filed[0].count = 0; for(int i=1; i<=m; i++) { for(int j=1; j<=n; j++) { filed[nIndex].x = i; filed[nIndex].y = j; cin >> filed[nIndex].count; //读入一个就排序一个 for(int k=1; k<nIndex; k++) { if(filed[k].count<filed[nIndex].count) { swap(filed[k],filed[nIndex]); } } nIndex++; } } for(int i=0; i<nIndex-1; i++) { int time = minPath(filed[i], filed[i+1])+1; if(time + filed[i+1].x > k || filed[i+1].count == 0) // 不够时间采集下一个坑的花生,或者所有花生均已采集完毕则退出 { break; } ans += filed[i+1].count; k -= time; } cout << ans; return 0; } ```
by nangongmazha @ 2020-02-07 23:07:19


@[Alex_Wei](/user/123294) 我哪里理解错了,请指正。后面我回复了我的代码以及疑问,谢谢
by nangongmazha @ 2020-02-07 23:09:01


![](https://cdn.luogu.com.cn/upload/image_hosting/onwng0c4.png)
by qjyzLfy @ 2020-02-07 23:36:41


| 下一页