牛客网训练部队java_训练部队
对不住大家了,之前由于牛客测试样例问题有一种情况没有考虑到,虽然ac了但是ac不是
目的,我们要追求严谨性,吐曹一秒牛客的测试样例。这里贴出更改之后的代码,更改处
有标记,这里对大家说声抱歉,同时提醒大家注意排除所有情况以及对牛客的答案要仔细
思考。
/* ***********************************************
Author :wsw
Created Time :2017年05月21日 星期日 22时55分09秒
TASK :Algorithm/date/牛客网/GG/xunlianbudui.cpp
LANG :C++
************************************************ */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct soder{
int x;
int y;
};
int comp(soder s1,soder s2)
{
return s1.x-s2.x!=0?s1.x
}
int main()
{
int n,z,q;
cin >> n;
soder ant[n];
for(int i=0;i
cin >> z >> q;
ant[i].x=z;
ant[i].y=q;
}
sort(ant,ant+n,comp);
int max = 0;
int index = 0;
int cha = 0;
for(int i=0;i
if(ant[i].x+ant[i].y>=max||ant[i].x+ant[i].y+cha>=max){
max = ant[i].x+ant[i].y;
cha = ant[i].y-ant[i].x;
index = i;
}
//此处判断战斗力相同情况下的情况
if(i>0&&ant[i].x==ant[i-1].x)
{
max = 0;
}
}
long res = max;
if(res>0){
for(int j = index-1;j>=0;j--){
if(ant[j].y>ant[j].x){
res += ant[j].y-ant[j].x;
}
}
cout << res << endl;
}else{
cout << 0 << endl;
}
return 0;
} /* ***********************************************
Author :wsw
Created Time :2017年05月21日 星期日 22时55分09秒
TASK :这道题其实思想很简单,需要点数学功底,搞明白潜力型的总值是固定的,只需要找到一个最合适的
战斗型人才就行 LANG :C++
************************************************ */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct soder{
int x;
int y;
};
int comp(soder s1,soder s2)
{
return s1.x-s2.x!=0?s1.x
}
int main()
{
int n,z,q;
cin >> n;
soder ant[n];
for(int i=0;i
cin >> z >> q;
ant[i].x=z;
ant[i].y=q;
}
sort(ant,ant+n,comp);
//cout << " ssss " << endl;
int max = 0;
int index = 0;
int cha = 0;
for(int i=0;i
if(ant[i].x+ant[i].y>=max||ant[i].x+ant[i].y+cha>=max){
max = ant[i].x+ant[i].y;
cha = ant[i].y-ant[i].x;
index = i;
}
}
long res = max;
for(int j = index-1;j>=0;j--){
if(ant[j].y>ant[j].x){
res += ant[j].y-ant[j].x;
//cout << res << "+++" << endl;
}
}
cout << res << endl;
return 0;
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
