HITACorz @ 2019-10-04 22:14:52
#include<iostream>
#include<algorithm>
using namespace std;
struct tt{
int xi;//hight
int yi;//strength
};
bool comparisonxi(tt a,tt b){
return a.xi<b.xi;
}
bool comparisonyi(tt a,tt b){
return a.yi<b.yi;
}
int main()
{
const int MAX=5100;
tt tao[MAX];
tt nw[MAX];
int n,a,s,xi,yi,b;
int i;
int num=0,temp=0;
int k;
cin>>n>>s>>a>>b;
for(i=1;i<n;i++)
{
cin>>tao[i].xi>>tao[i].yi;
}
sort(tao+1,tao+n,comparisonxi);
for(i=1;i<=n;i++)
{
if(tao[i].xi<=(a+b))
{
nw[i].xi=tao[i].xi;
nw[i].yi=tao[i].yi;
num++;
}
else break;
}
sort(nw+1,nw+num+1,comparisonyi);
k=num;
for(i=1;i<=num;i++)
{
if(b>=0&&k>0)
{
b=b-nw[i].yi;
temp++;
k--;
}
else break;
}
cout<<temp;
return 0;
}
by charm1 @ 2019-10-04 22:25:22
#include <bits/stdc++.h>
using namespace std;
int n,s,get,ans,i;
struct app
{
int high,cost;
}a[10001];
bool cmp(app x,app y)
{
// cout<<++i<<" ";
return x.cost<y.cost;
}
int main() {
int k,j;
cin>>n>>s;
cin>>k>>j;
get=k+j;
for(k=1;k<=n;k++)
{
cin>>a[k].high>>a[k].cost;
if(get<a[k].high||s<a[k].cost)
{
k--;
n--;
}
}
// cout<<n<<endl;
// cout<<"KO"<<endl;
sort(a+1,a+n+1,cmp);
// cout<<"OK"<<endl;
for(k=1;k<=n&&s>0;k++)
if(s>=a[k].cost)
{
ans++;
s-=a[k].cost;
}
cout<<ans<<endl;
return 0;
}
by HITACorz @ 2019-10-04 22:34:50
@charm1 可不可以看一下我的代码哪里有错误呢?
by 仗剑_天涯 @ 2019-10-04 22:37:13
@JryACtrying
你这个码风跟我不一样,,看不了
by HITACorz @ 2019-10-04 22:38:26
@仗剑走天涯_ZHX 我直接模拟……………………
by charm1 @ 2019-10-04 22:42:07
别在主函数定义数组
by HITACorz @ 2019-10-04 22:42:20
@仗剑走天涯_ZHX 我的代码太复杂了,不如各位大佬的简介。我是初学者,emm……唉,太难了
by charm1 @ 2019-10-04 22:42:25
不然洛谷会炸
by HITACorz @ 2019-10-04 22:44:28
@charm1 把数组定义到主函数以外,还是一样的结果两个WA一个RE
by charm1 @ 2019-10-04 22:46:58
@JryACtrying 定义全局变量
by HITACorz @ 2019-10-04 22:50:47
@charm1
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX=5100;
struct tt{
int xi;//hight
int yi;//strength
};
tt tao[MAX];
tt nw[MAX];
bool comparisonxi(tt a,tt b){
return a.xi<b.xi;
}
bool comparisonyi(tt a,tt b){
return a.yi<b.yi;
}
int main()
{
int n,a,s,xi,yi,b;
int i;
int num=0,temp=0;
int k;
cin>>n>>s>>a>>b;
//scanf("%d%d%d%d",&n,&s,&a,&b);
for(i=1;i<n;i++)
{
cin>>tao[i].xi>>tao[i].yi;
// scanf("%d%d",&xi,&yi);
}
sort(tao+1,tao+n,comparisonxi);
for(i=1;i<=n;i++)
{
if(tao[i].xi<=(a+b))
{
nw[i].xi=tao[i].xi;
nw[i].yi=tao[i].yi;
num++;
}
else break;
}
sort(nw+1,nw+num+1,comparisonyi);
k=num;
for(i=1;i<=num;i++)
{
if(b>=0&&k>0)
{
b=b-nw[i].yi;
temp++;
k--;
}
else break;
}
cout<<temp;
return 0;
}
改成了全局变量还是一样的结果,我哭了……