答案:牛客周赛 Round 83(A-E)
比赛链接
https://ac.nowcoder.com/acm/contest/102896
和猫猫一起起舞!
评价
签到题1,if判断即可。
AC代码
#include<bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n';
#define il inline
using namespace std;
using ll = long long;
using ull = unsigned long long;
char a;
int main(){
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
ios::sync_with_stdio(0),cout.tie(0),cin.tie(0);
cin>>a;
if(a == 'U' || a == 'D'){
cout<<'L';
}else{
cout<<'U';
}
return 0;
}
冒险猫猫参上!!
评价
签到题2,用1和2构造即可。
AC代码
#include<bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n';
#define il inline
using namespace std;
using ll = long long;
using ull = unsigned long long;
char a;
int main(){
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
ios::sync_with_stdio(0),cout.tie(0),cin.tie(0);
cin>>a;
if(a == 'U' || a == 'D'){
cout<<'L';
}else{
cout<<'U';
}
return 0;
}
泉神,启动!!!
评价
签到题3,
设y为 10^x.size()+1即可。
AC代码
#include<bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n';
#define il inline
using namespace std;
using ll = long long;
using ull = unsigned long long;
int T;
string s;
int main(){
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
ios::sync_with_stdio(0),cout.tie(0),cin.tie(0);
cin>>T;
while(T--){
cin>>s;
int n = s.size();
cout<<1;
for(int i = 1;i <= n-1;i++)cout<<0;
cout<<1<<'\n';
}
return 0;
}
大预言家!!!!
评价
有意思的数学题,貌似过D的人没过E的多?
AC代码
#include<bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n';
#define il inline
#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
int t,n;
signed main(){
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
ios::sync_with_stdio(0),cout.tie(0),cin.tie(0);
cin>>t;
while(t--){
cin>>n;
int p=(((int)sqrt(n+.5))-1)/2*2+1,x=p/2,y=p/2;
int d = min(n,1ll);
n-=d+p*p,x+=d;
d=min(n,p);n-=d;y-=d,d=min(n,p+1);n-=d;x-=d;
d=min(n,p+1);n-=d;y+=d,d=min(n,p+1);n-=d;x+=d;
cout<<x<<' '<<y<<'\n';
}
return 0;
}
全都要!!!!!
评价
一道吃思路的DP。
AC代码
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
using ll = long long;
ll calc(int n, int k, vector<int>& a) {
vector<vector<ll>> dp(k + 1, vector<ll>(n + 1, -inf));
dp[0][0] = 0;
for (int i = 1; i <= k;i++) {
for (int j = 0; j <= n;j++) {
if (dp[i - 1][j] != -inf) {
for (int m = 1; m <= 6;m++) {
if (j + m <= n) {
dp[i][j + m] = max(dp[i][j + m], dp[i - 1][j] + a[j + m - 1]);
}
}
}
}
}
ll m = -inf;
for (int j = 1; j <= n; ++j) {
m = max(m, dp[k][j]);
}
return m;
}
int main() {
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
ios::sync_with_stdio(0),cout.tie(0),cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n;i++) cin >> a[i];
cout << calc(n, k, a) << '\n';
return 0;
}

浙公网安备 33010602011771号