Codeforces-Round#574 Div2
A题 Drinks Choosing
判断奇偶
#include<bits/stdc++.h>
using namespace std;
int arr[2000];
int main()
{
int n,k;cin>>n>>k;int rem=0;
for(int i=0;i<n;i++)
{
int num;
cin>>num;arr[num]++;
}
for(int i=1;i<=k;i++)
{
if((arr[i]&1))
{
rem++;
}
}
cout<<n-rem/2<<endl;
return 0;
}
B题 Sport Mafia
水题
#include <iostream>
#include <cmath>
#define LL long long
using namespace std;
int main(){
LL n,k;
cin >> n >> k;
LL tmp = 2*(k+n);
LL maxn = 1ll*sqrt(tmp)+1;
while(maxn){
if(maxn*(maxn+3) == tmp){
cout << n-maxn << endl;
break;
}
maxn--;
}
return 0;
}
C题 Basketball Exercise
简单dp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,h[2][200020],dp[2][200020];
int main()
{
cin>>n;
for(int i=0;i<n;i++)
cin>>h[0][i];
for(int i=0;i<n;i++)
cin>>h[1][i];
dp[0][0]=h[0][0];dp[1][0]=h[1][0];
for(int i=1;i<=n;i++)
{
dp[0][i]=max(h[0][i]+dp[1][i-1],dp[0][i-1]);
dp[1][i]=max(h[1][i]+dp[0][i-1],dp[1][i-1]);
}
cout<<max(dp[0][n],dp[1][n])<<endl;
return 0;
}
D1题 Submarine in the Rybinsk Sea (easy edition)
\(f(a_1,a_2)+f(a_2,a_1)=f(a_1,a_1)+f(a_2,a_2)\),即\(sum=\sum_{i=1}^n{f(a_i,a_i)}*n\)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sum=0;
ll pow(ll step)
{
ll ans=1;
while(step--)
{
ans=(ans*10)%998244353;
}
return ans;
}
ll get(ll num)
{
ll ans=0,step=0;
while(num>0)
{
step++;
int d=num%10;
num/=10;
ans+=(d*(pow(step*2-1)%998244353)+d*(pow(step*2-2)%998244353))%998244353;
}
return ans;
}
int main()
{
int n;
cin>>n;int nn=n;
while(n--)
{
ll num;cin>>num;
sum+=get(num)%998244353;
}
sum=abs(sum);
cout<<(sum*nn)%998244353<<endl;
return 0;
}
D2题 Submarine in the Rybinsk Sea (hard edition)
按位运算,若12 和3 则,\(ans=f(2,3)+1*2*10^2\)
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FOR2(i,a,b) for(int i=a;i<=b;i++)
#define sync ios::sync_with_stdio(false);cin.tie(0)
#define ll long long
using namespace std;
typedef struct{
ll num;
ll len;
}NUM; NUM nums[100010];
ll arr[100010];
ll p10[30];
ll mod=998244353 ;
ll ans=0;
ll getlen(ll a)
{
int len=0;
while(a>0)
{
a/=10;
len++;
}
arr[len]++;
return len;
}
int main()
{
sync;
p10[1]=1;
for(int i=2;i<30;i++)
{
p10[i]=(p10[i-1]*10)%mod;
}
int n;cin>>n;
for(int i=0;i<n;i++)
{
cin>>nums[i].num;
nums[i].len=getlen(nums[i].num);
}
for(int i=0;i<n;i++)
{
ll b=nums[i].num;
int pos=0;
while(b)
{
ll c=b%10;b/=10;pos++;
for(int j=1;j<=10;j++)
{//其他数的位数
if(j>=pos)
{
ans+=c*arr[j]*p10[pos*2];
ans+=c*arr[j]*p10[pos*2-1];
}
else if(j<pos)
{
ans+=2*c*arr[j]*p10[pos+j];
}
}
ans=ans%mod;
}
}
cout<<ans%mod<<endl;
return 0;
}