Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)

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;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值