A题,很简单吧。可以说是。
- 思路
9个一循环吧。
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
typedef long long ll;
typedef pair<int, int> PII;
ll a[N];
int hsh[N];
int m;
void solve()
{
int a,b,c;
cin>>a>>b>>c;
int res=a+b+c;
if(res%9!=0)
cout<<"NO"<<endl;
else
{
int x=res/9;
if(x<=a&&x<=b&&x<=c)
cout<<"YES"<<endl;
else
{
cout<<"NO"<<endl;
}
}
}
int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
}
B题
-
题意
-
思路
偶数,放1,级数放a【i】;或者奇数放1,偶数放a【i】;
因为这样奇数或者偶数,为0.偶数或者奇数的差会小于s/2;
但是不一定哪一个小于s/2,所以要测试一下,是奇数放1还是偶数放1.
两个两个的看,无非有一个会小于两者之和。
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
typedef long long ll;
typedef pair<int, int> PII;
ll a[N];
int hsh[N];
int m;
ll b[N];
void solve()
{
int n;
cin >> n;
ll sum = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum += a[i];
}
ll s = 0;
for (int i = 1; i <= n; i++)
{
if (i % 2)
{
b[i] = 1;
s +=(a[i]- b[i]);
}
else
{
b[i] = a[i];
s += (a[i]-b[i]);
}
}
if (s * 2 > sum)
{
for (int i = 1; i <= n; i++)
{
if (i % 2 == 0)
{
b[i] = 1;
}
else
{
b[i] = a[i];
}
}
}
for (int i = 1; i <= n; i++)
cout << b[i] << " ";
cout << endl;
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
}
D题
- 题意
- 思路
- 代码
#include <iostream>
#include <cstdio>
const int maxn=2e5+7;
using namespace std;
int T,n,sum,l,r;
int a[maxn];
int main()
{
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",&a[i]);
a[n+1]=2*n+1;
l=0,r=0;
sum=0;
for (int i=1;i<=n;i++)
{
sum+=a[i]-a[i-1]-1;
if (!sum) l++;
else sum--;
}
sum=0;
for (int i=n;i>0;i--)
{
sum+=a[i+1]-a[i]-1;
if (!sum) r++;
else sum--;
}
printf("%d\n",n-r-l+1);
}
}
C题
(模拟题)
题意
思路
代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
ll T[N], X[N];
void solve()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> T[i] >> X[i];
ll nowx = 0, end = 0;
ll res = 0;
T[n + 1] = 2e10;
for (int i = 1; i <= n; i++)
{
if (nowx == end) end = X[i];
ll l = nowx, r;
if (nowx > end)
{
if (nowx - end >= T[i + 1] - T[i])
{
nowx -= T[i + 1] - T[i];
}
else
nowx = end;
}
else
{
if (end - nowx >= T[i + 1] - T[i])
nowx += T[i + 1] - T[i];
else
nowx = end;
}
r = nowx;
if (l > r)
swap(l, r);
if (l <= X[i] && X[i] <= r)
res++;
}
cout << res << endl;
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
}