比赛链接:https://codeforces.com/contest/2031
明天再补题面,A题漏看题意了卡了到19分才过;C题知道9,16,25的情况,但是一直没去想27,卡了50多分钟;D题最后30秒交,有个判断删了就可以过,差点点。今天运势不佳,各种错误并发,太累了,明天再补D思路。
A. Penchick and Modern Monument
思路:就是看哪个数最多,然后n-这个最大值即可。
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#define ll long long
#define lowbit(x) (x & -x)
#define endl "\n"// 交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
ll ksm(ll x, ll y)
{
ll ans = 1;
while (y)
{
if (y & 1)
{
ans = ans % mod * (x % mod) % mod;
}
x = x % mod * (x % mod) % mod;
y >>= 1;
}
return ans % mod % mod;
}
ll gcd(ll x, ll y)
{
if (y == 0)
return x;
else
return gcd(y, x % y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll dp[500][55];
ll a[250000];
int main()
{fio();ll t;cin>>t;while(t--){ll n;cin>>n;ll ans=99999999999;for(ll i=1;i<=n;i++){cin>>a[i];for(ll j=1;j<=50;j++){if(a[i]==j)dp[i][j]=0;else dp[i][j]=1;}for(ll j=1;j<=50;j++){ll u=99999999;for(ll k=1;k<=j;k++){u=min(dp[i][k],u);}dp[i][j]=dp[i-1][j]+u;if(i==n)ans=min(ans,dp[i][j]);}}cout<<ans<<endl;}
}
B. Penchick and Satay Sticks
思路:通过题目要求可以推得,如果一个数离他原本位置距离大于1,则一定无解
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#define ll long long
#define lowbit(x) (x & -x)
#define endl "\n"// 交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
ll ksm(ll x, ll y)
{
ll ans = 1;
while (y)
{
if (y & 1)
{
ans = ans % mod * (x % mod) % mod;
}
x = x % mod * (x % mod) % mod;
y >>= 1;
}
return ans % mod % mod;
}
ll gcd(ll x, ll y)
{
if (y == 0)
return x;
else
return gcd(y, x % y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll a[250000];
int main()
{fio();ll t;cin>>t;while(t--){ll n;cin>>n;map<ll,ll>q;ll ans=0;for(ll i=1;i<=n;i++){cin>>a[i];if(abs(a[i]-i)<=1)continue;else ans=1;}if(ans==0)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
}
C. Penchick and BBQ Buns
思路:偶数直接1 ,1 ,2, 2,3,3...即可,奇数,考虑吧出现x1x1+x2x2=(x1+x2)*(x1+x2)情况即可,只能3,4,5存在,所以对于长度等于27的数组构造方法,可以是先9,16,26相同为1,然后27,23等于2,其余空格为3,3;4,4慢慢填进去即可,对于大于27的奇数数组,多的部分直接把多出来的部分按照偶数数组的形式放置即可
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#define ll long long
#define lowbit(x) (x & -x)
#define endl "\n"// 交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
ll ksm(ll x, ll y)
{
ll ans = 1;
while (y)
{
if (y & 1)
{
ans = ans % mod * (x % mod) % mod;
}
x = x % mod * (x % mod) % mod;
y >>= 1;
}
return ans % mod % mod;
}
ll gcd(ll x, ll y)
{
if (y == 0)
return x;
else
return gcd(y, x % y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll a[250000];
int main()
{fio();ll t;cin>>t;while(t--){ll n;cin>>n;ll k=n;for(ll i=1;i<=n;i++)a[i]=0;if(n&1){if(n>=27){ll cnt=1;while(n>27){a[n]=cnt;a[n-1]=cnt;n-=2;cnt++;}a[27]=a[23]=cnt;cnt++;a[26]=a[10]=a[1]=cnt;cnt++;for(ll i=1;i<=27;i++){if(a[i]==0){a[i]=cnt;a[i+1]=cnt;cnt++;}}for(ll i=1;i<=k;i++)cout<<a[i]<<" ";cout<<endl;}else cout<<-1<<endl;}else {ll cnt=1;for(ll i=1;i<=n;i+=2){cout<<cnt<<" "<<cnt<<" ";cnt++;} cout<<endl;}}
}
D. Penchick and Desert Rabbit
思路:
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#define ll long long
#define lowbit(x) (x & -x)
#define endl "\n"// 交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
ll ksm(ll x, ll y)
{
ll ans = 1;
while (y)
{
if (y & 1)
{
ans = ans % mod * (x % mod) % mod;
}
x = x % mod * (x % mod) % mod;
y >>= 1;
}
return ans % mod % mod;
}
ll gcd(ll x, ll y)
{
if (y == 0)
return x;
else
return gcd(y, x % y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll a[654000];
ll b[625000];
ll pre[625000];
ll sub[625000];
int main()
{
fio();ll t;cin>>t;while(t--){ll n;cin>>n;//ll ans=0;sub[n+1]=999999999999;for(ll i=1;i<=n;i++)cin>>a[i],pre[i]=max(a[i],pre[i-1]),b[i]=a[i];ll u=99999999999;ll ans;for(ll i=n;i>=1;i--){if(i==n){u=min(u,a[i]);ans=max(a[i],pre[i-1]);b[i]=ans;}if(pre[i-1]==ans||a[i]==ans){b[i]=ans;u=min(u,a[i]);}else if(pre[i-1]>u||a[i]>u){b[i]=ans;u=min(u,a[i]);} else {ans=max(pre[i-1],a[i]);u=a[i];b[i]=ans;}}for(ll i=1;i<=n;i++)cout<<b[i]<<" ";cout<<endl;}
}