猿辅导编程第一题什么思路
我的思路是,用优先队列,取出来顶上前三个a,b,c那么如果c==0直接返回res,否则res =c。
int main()
{
int n;
cin >> n;
while (n--) {
int t;
cin >> t;
priority_queue<int> p;
while(t--) {
int m;
cin >> m;
p.push(m);
}
int a,b,c;
int res = 0;
while(p.size()>=3) {
a = p.top();
p.pop();
b = p.top();
p.pop();
c = p.top();
p.pop();
if (c == 0)
break;
else {
a = a - c;
b = b - c;
p.push(a);
p.push(b);
res = c;
}
}
cout << res << endl;
}
return 0;
}#猿辅导##笔试题目#
int main()
{
int n;
cin >> n;
while (n--) {
int t;
cin >> t;
priority_queue<int> p;
while(t--) {
int m;
cin >> m;
p.push(m);
}
int a,b,c;
int res = 0;
while(p.size()>=3) {
a = p.top();
p.pop();
b = p.top();
p.pop();
c = p.top();
p.pop();
if (c == 0)
break;
else {
a = a - c;
b = b - c;
p.push(a);
p.push(b);
res = c;
}
}
cout << res << endl;
}
return 0;
}#猿辅导##笔试题目#