A题
- 题意
比赛的时候卡了,我去,这个要求看看给定一个数,有没有奇数因数。 - 我的代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
ll a[N];
void solve()
{
ll n;
cin>>n;
if(n==2)
{
cout<<"NO"<<endl;
return;
}
bool flag=false;
while(n%2==0&&n>2)
{
n/=2;
}
//cout<<n<<endl;
if(n%2==1)
flag=true;
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
int main()
{
for(ll i=1;i<=1e5;i++)
a[i]=i*2+1;
int t;
cin>>t;
while (t--)
{
solve();
}
}
- 官方
- 官方代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
void solve() {
ll n;
cin >> n;
if (n & (n - 1)) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
B题
- 题意,给你一个数,看看能否由2020和2021组成。
- 本人被hack的代码,但是今天交上去依然AC,可能
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
void solve()
{
ll n;
cin>>n;
int x=n/2020+1,y=n/2021+1;
bool flag=false;
for(ll i=0;i<=x;i++)
{
for(ll j=y;j>=0;j--)
{
if(i*2020*1ll+j*2021*1ll==n)
{
flag=true;
break;
}
}
}
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
int main()
{
int t;
cin>>t;
while (t--)
{
solve();
}
}
- 仔细考虑过的代码。(很可惜,超时了)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
void solve()
{
ll n;
cin>>n;
int x=n/2020,y=n/2021;
bool flag=false;
for(ll i=0;i<=x;i++)
{
for(ll j=y;j>=0;j--)
{
if(i*2020*1ll+j*2021*1ll==n)
{
flag=true;
break;
}
}
}
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
int main()
{
int t;
cin>>t;
while (t--)
{
solve();
}
}
- 官方
C题 - 题意
给个样例
- 思路
不考虑不符合情况的就是从k个里选两个,然后减去不符合情况的,zzy太强了。 - 代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int a[N],b[N];
int hsh1[N],hsh2[N];
void solve()
{
ll n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= k; i++)
cin >> a[i],hsh1[a[i]]++;
for (int i = 1; i <= k; i++)
cin >> b[i],hsh2[b[i]]++;
ll res = 0;
ll x=max(n,m);
for(ll i=1;i<=x;i++)
{
ll x1=hsh1[i];
if(hsh1[i])
res+=x1*(x1-1)/2;
ll y=hsh2[i];
if(hsh2[i])
res+=y*(y-1)/2;
}
res=k*(k-1)/2-res;
cout << res << endl;
for(int i=1;i<=k;i++)
{
hsh1[a[i]]=0;
hsh2[b[i]]=0;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
if(t==1000-11)
cout<<endl;
solve();
}
}`
注,一定要开long long 啊。所有的只要涉及运算的数都要开。
D题
- 题意
就是给你一组数和一个数,看能否以最小的代价组成这个数。每个数的代价要么是1,要么是2. - 思路
E题
- 题意
- 思路
注:自己太菜了,
粘一个大佬题解
粘另一个大佬题解(这个还可以,上一个有点难理解)。