我试过但它给了我一个运行时错误...请提供给我代码 [英] I have tried but it gives me a run time error...please provide me code

查看:126
本文介绍了我试过但它给了我一个运行时错误...请提供给我代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您需要找到花园底部的最大可能边长,以便移除住宅地块的总费用不超过B.



输入格式输入1:它将是一个字符串,它表示由一个逗号分隔的两个整数,分别代表M和N.输入2:它将是整数B,即您可以承受的最大成本(即您的预算)。这是删除ith情节的成本。输入3:它将是整数P,列表中的住宅图。输入4:它将是字符串数组,其中:数组的第一行告诉数组中元素的总数,即下一个P行中的每一行描述住宅图。这些线的第i个描述了第i个图。每行由5个整数组成:Xi1,Yi1,Xi2,Yi2和Ci用单个逗号分隔。它们分别代表图的最底部,最左边的单元的坐标,最顶部和最顶部的坐标。最右边的单元格,以及删除绘图的成本。网格上最左边的最左边的单元格具有坐标(1,1),最右边的单元格具有坐标(M,N)。



1< = Xi1 < = Xi2< = M,第i个住宅区1的最左边和最右边的单元的X坐标< = Yi1< = Yi2< = N,第i个住宅的最底部和最顶部的单元的Y坐标曲线



约束条1< = M,N <= 1,000,000 1< = Ci <= 7,000 0 <= B <= 1,00,000 1< ; = P <= 1,00,000



输出格式它将是一个整数,它告诉花园底部的最大长度,以便移除总成本样本不超过B.样本TestCase 1输入6,9 42 5 5 4,1,6,3,12 3,6,5,6,9 1,3,3,8,24 3,8,6,9 ,21 5,1,6,2,20输出4说明:花园基地的两个可能位置,两个都有一个长度为4的边,这是花园底部的最大可能长度。因此输出将为4.



样本TestCase 2输入6,9 0 5 5 4,1,6,3,12 3,6,5,6, 9 1,3,3,8,24 3,8,6,9,21 5,1,6,2,20输出



我是什么尝试过:



You need to find the maximum possible side length of the base of the garden such that the total cost of removing residential plot does not exceed B.

Input Format Input 1: It will be string which tells two integers separated by a single comma that represent M and N respectively. Input 2: It will be the integer B, the maximum cost you can afford (i.e., your budget). It is the cost of removing ith plot. Input 3: It will be the integer P, the residential plots found in the list. Input 4: It will be string array where: The first line of the array tells the total number of elements in the array i.e. Each of the next P lines describes a residential plot. The ith of these lines describes the ith plot. Each line consists of 5 integers: Xi1, Yi1, Xi2, Yi2, and Ci separated by single comma. They represent respectively the coordinates of the bottommost, leftmost cell of the plot, the coordinates of the topmost & rightmost cell of the plot, and the cost of removing the plot. The bottommost, leftmost cell on the grid has coordinates (1, 1) and the topmost, rightmost cell has coordinates (M, N).

1 <= Xi1 <= Xi2 <= M, X coordinates of the leftmost and the rightmost cells of the ith residential plot 1 <= Yi1 <= Yi2 <= N, Y coordinates of the bottommost and the topmost cells of the ith residential plot

Constraints 1 <= M, N <= 1,000,000 1 <= Ci <= 7,000 0 <= B <= 1,00,000 1<= P <= 1,00,000

Output Format It will be an integer that tells the maximum length of the base of the garden such that the total cost of removing plots does not exceed B. Sample TestCase 1 Input 6,9 42 5 5 4,1,6,3,12 3,6,5,6,9 1,3,3,8,24 3,8,6,9,21 5,1,6,2,20 Output 4 Explanation: two possible locations for the garden base, both having a side of length 4 which is the maximum possible length of the base of the garden. Hence the output will be 4.

Sample TestCase 2 Input 6,9 0 5 5 4,1,6,3,12 3,6,5,6,9 1,3,3,8,24 3,8,6,9,21 5,1,6,2,20 Output

What I have tried:

include <iostream>
include <bits.h>
using namespace std;

typedef long long int ll; typedef long double db;

int main() { ll n,m;char ch;ll i,j,k; cin>>n>>ch>>m; ll a[n+1][m+1]; ll cost,plots,ui,r1,r2,c1,c2,plotcost; cin>>cost>>plots>>ui; vector<ll> costv; costv.push_back(0LL); ll mp[n+1][m+1]; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) {

mp[i][j]=0;//<<" "; } //cout<<endl; }="" while(plots--)="" {="" cin="">>r1>>ch>>c1>>ch>>r2>>ch>>c2>>ch>>plotcost; costv.push_back(plotcost); ll yu=costv.size()-1; for(i=r1;i<=r2;i++) { for(j=c1;j<=c2;j++) { mp[i][j]=yu; } } } ll len; ll maxlength=0; ll l;ll s=0; //cout<<n<<" "<<m<<endl;

for(len=1;len<=6;len++) { for(i=1;i<=n-len+1;i++) { for(j=1;j<=m-len+1;j++) { ll costsum=0; set<ll> se; for(k=i;k<i+len;k++) { for(l=j;l<j+len;l++) { se.insert(mp[k][l]); } } for(auto it=se.begin();it!=se.end();it++) { costsum+=costv[*it]; } if(costsum<=cost) { maxlength=max(maxlength,len); } } } } cout<<maxlength<<endl;

return 0; }

推荐答案

这是与解决此欠幅错误代码 - C / C ++ / MFC讨论板 [ ^ ]。您是否创建了第二个用户帐户只是为了重新发布您的问题,而不是提供我们要求您提供的正确详细信息?
This is the same question as Solve this runt time error code - C / C++ / MFC Discussion Boards[^]. Did you create this second user account just to repost your question, instead of providing the proper details that we have asked you for?


首先要明确并选择一种语言。 />
First of all make your mind and choose a language.
Quote:

我试过但它给了我一个运行时错误...

I have tried but it gives me a run time error...



给我们提供错误信息和位置以获取有关代码的帮助。


Give us error message and position to get help on your code.

引用:

请提供给我代码



LOL请提供资金:-)



当您寻求帮助时,显示不可读的代码并不是一个好主意。

我要求资金重新格式化你的代码。



据我所知,要求来自挑战网站,所以唯一感兴趣的是知道你是否可以解决问题。

在这类问题中,蛮力永远不是解决方案,你必须设计一个有效的算法。通常,纸张和铅笔是您解决问题的小实例所需要的。需要较少工作的算法就是你的答案。



- 学习一种或多种分析方法,E.W。Djikstra / N. Wirth Stepwize Refinement / top-Down方法是一个良好的开端。

Structured Programming.pdf [ ^ ]

https://en.wikipedia。 org / wiki / Top-down_and_bottom-up_design [ ^ ]

https://en.wikipedia.org/wiki/Structured_programming [ ^ ]

https://en.wikipedia.org/wiki/Edsger_W._Dijkstra [ ^ ]

https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF [ ^ ]

- 学习算法和数据结构。


LOL please provide money :-)

Showing unreadable code is not a good idea when you ask for help.
I request money just to reformat your code.

As far as I can see, the requirement is from a challenge site, so the only interest is to know id you can solve the problem or not.
In this kind of problem, brute force is never the solution, you have to devise an efficient algorithm. Usually, sheet of paper and pencil is what you need to solve small instances of the problem. The algorithm that need less work is your answer.

- Learn one or more analyze methods, E.W. Djikstra/N. Wirth Stepwize Refinement/top-Down method is a good start.
Structured Programming.pdf[^]
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[^]
https://en.wikipedia.org/wiki/Structured_programming[^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[^]
- Learn Algorithms and Data-Structures.


这很明显这是你的作业。



请提供代码?绝对不是。



我们提供帮助 - 对于那些真正为这个问题付出一些努力的人。这意味着他们对解决方案的特定部分有特定的问题。



如果你想让别人为你做你的工作,做你要做的事情你想为你做的任何其他工作: 雇人。
It's pretty obvious this is your homework.

Please provide code? Absolutely not.

We provide help - for someone's who's really put some work into the problem. That means they'd have specific questions for a specific part of their solution.

If you want someone to do your work for you, do what you'd do for any other kind of work you want done for you:   hire someone.


这篇关于我试过但它给了我一个运行时错误...请提供给我代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆