森森鸭 @ 2019-08-02 15:35:42
话不多说,直接粘代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int aps,sl,h1,h2,h;
cin>>aps>>sl>>h1>>h2;
h=h1+h2;
int st[5010];
int c=1,hs=0,ans=0;
for(int i=1;i<=aps;i++)
{
int a,b;
cin>>a>>b;
if(a<=h) st[c]=b,c++;
}
sort(st+1,st+c-1);
for(int i=1;i<=aps;i++)
{
if(hs+st[i]<=sl)
{
hs+=st[i];
ans++;
}
else
{
cout<<ans;
break;
}
}
return 0;
}
求救aaaaaaa
by Eason_AC @ 2019-08-02 15:38:41
您的sort?应该是sort(st+1,st+c+1)
才对吧
by Eason_AC @ 2019-08-02 15:39:40
还有您的数组要开到10010
by Eason_AC @ 2019-08-02 15:39:45
@森森鸭
by 森森鸭 @ 2019-08-02 15:45:44
@Eason_AC 谢谢!!!!!
by 森森鸭 @ 2019-08-02 15:48:39
@Eason_AC #4wa声一片,有点衰
#include <bits/stdc++.h>
using namespace std;
int main()
{
int aps,sl,h1,h2,h;
cin>>aps>>sl>>h1>>h2;
h=h1+h2;
int st[10010];
int c=1,hs=0,ans=0;
for(int i=1;i<=aps;i++)
{
int a,b;
cin>>a>>b;
if(a<=h) st[c]=b,c++;
}
sort(st+1,st+c);
for(int i=1;i<=c-1;i++)
{
if(hs+st[i]<=sl)
{
hs+=st[i];
ans++;
}
else
{
cout<<ans;
break;
}
}
return 0;
}
by Eason_AC @ 2019-08-02 15:51:48
你干脆看一下我的代码吧,你这个代码写的好像有点乱
#include <iostream>
#include <algorithm>
using namespace std;
int m[10000],n,s,a,b,x,y,k,t=0,d,c,ans=0;
int main() {
cin>>n>>s>>a>>b;
for(int i=1; i<=n; i++) {
cin>>x>>y;
if(a+b>=x) {
m[++t]=y;
}
}
sort(m+1,m+t+1);
c=1;
while(s-m[c]>=0 &&c<=t) {
ans++;
s-=m[c];
c++;
}
cout<<ans;
return 0;
}
@森森鸭
by 本号停止使用 @ 2019-08-02 15:52:39
@森森鸭 下数据,特判「不要学我,这是不正当手段
by 森森鸭 @ 2019-08-02 15:52:53
@Eason_AC 好的谢谢啦!!?
by 森森鸭 @ 2019-08-02 16:01:21
@卢禺佟666 嘻嘻嘻好的学到了,现在ac啦以后有不会的特判嘿嘿?
by 本号停止使用 @ 2019-08-02 16:03:10
@森森鸭 emmm……