A. Sum of 2050
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
const double eps = 1e-6;
const int mod = 998244353;
const int N = 1e6 + 10;
const int M = 211;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
int dp[N];
void solve(){
int t;
cin>>t;
while(t--){
ll n;
cin>>n;
if(n%2050) cout<<"-1"<<endl;
else{
n/=2050;
ll res=0;
while(n){
res+=n%10;
n/=10;
}
cout<<res<<endl;
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
B - Morning Jogging
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
const double eps = 1e-6;
const int mod = 998244353;
const int N = 1e6 + 10;
const int M = 211;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
int dp[M*M];
int mp[M][M];
bool vis[M][M];
void solve(){
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
int tot=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>mp[i][j];
dp[++tot]=mp[i][j];
}
}
sort(dp+1,dp+1+tot);
int xx,yy;
int pos=0;
for(int i=1;i<=m;i++){
for(int x=1;x<=n;x++){
for(int y=1;y<=m;y++){
if(mp[x][y]==dp[i]&&!vis[x][y]){
xx=x;
yy=y;
break;
}
}
}
vis[xx][++pos]=1;
swap(mp[xx][pos],mp[xx][yy]);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cout<<mp[i][j]<<" ";
}
cout<<endl;
}
mem(vis,0);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
C - Fillomino 2
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
const double eps = 1e-6;
const int mod = 998244353;
const int N = 1e6 + 10;
const int M = 555;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
int n;
int mp[M][M];
int pos;
void DFS(int x,int y,int s,int e){
if(e==pos||x<1||x>n||y<1||y>n) return ;
if(mp[x][y]&&mp[x][y]!=s) return ;
mp[x][y]=s;
pos++;
DFS(x,y-1,s,e);
DFS(x+1,y,s,e);
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>mp[i][i];
for(int i=1;i<=n;i++){
pos=0;
DFS(i,i,mp[i][i],mp[i][i]);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
cout<<mp[i][j]<<" ";
}
cout<<endl;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}