A. Mean Inequality
Example
input
Copy
3
3
1 2 3 4 5 6
2
123 456 789 10
1
6 9
output
Copy
3 1 4 2 5 6
123 10 456 789
9 6
题意:将序列变为(a[i-1]+a[i+1])/2!=a[i];
题解:将序列排序sort一下,然后对半分,依次输出一个。
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int a[100];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=0;i<2*n;i++)
{
int x;
scanf("%d",&x);
a[i]=x;
}
sort(a,a+2*n);
for(int i=0;i<n;i++)
{
if(i==0)
{
cout<<a[i+n]<<" "<<a[i];
}
else
{
cout<<" "<<a[i+n]<<" "<<a[i];
}
}
cout<<endl;
}
return 0;
}
B. I Hate 1111
input
Copy
3 33 144 69
output
Copy
YES YES NO
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int a[100];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
if(n%11<=n/11/10)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}
C1. Potions (Easy Version)
Example
input
Copy
6 4 -4 1 -3 1 -3
output
Copy
5
题意:给出n瓶药水,开始你的生命值是0,你要喝这些药水保证喝的时候生命值始终为非零数。
题解:for循环暴力一下,和每瓶药水的时候判断一下生命值是否为小于零,如果小于零就将喝过的药水中负数最小的数减去。
困难版比简单版的n大,但是这个做法是O(n)的做法,时间不会超,所以简单和困难都一样。
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
priority_queue<int>q;
int n;
scanf("%d",&n);
int ans=0;
LL sum;
for(int i=0;i<n;i++)
{
int x;
scanf("%d",&x);
if(x<0)
{
q.push(-x);
}
if(i==0)
{
sum=x;
}
else
{
sum=sum+x;
}
ans++;
if(sum<0)
{
sum=sum+q.top();
q.pop();
ans--;
}
}
cout<<ans<<endl;
return 0;
}