首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >AtCoderBeginnerContest112

AtCoderBeginnerContest112

作者头像
xiaohejun
发布2020-02-17 23:33:13
2890
发布2020-02-17 23:33:13
举报

AtCoder Beginner Contest 112比赛链接

emm.第一次在AtCoder上的比赛. rank:754th rating:113. AC. WA.表示比赛时候的状态

A - Programming Education

AC

题目大意: 输入1的时候输出”Hello World”. 输入2的时候会输入a,b.计算a+b.

题解: emm.入门操作.beginner出这个题还是很不错的.

#include <bits/stdc++.h>
using namespace std;

int main(){
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0); cin.tie(0);
    int kind,a,b;
    while(cin >> kind){
        if(kind == 1){
            cout << "Hello World" << endl;
        } else {
            cin >> a >> b;
            cout << (a+b) << endl;
        }
    }
	return 0;
}

B - Time Limit Exceeded

AC

题目大意: 给两个数N,T. N组数.每组两个数$c_i$和$t_i$.求所有不超过T的$t_i$中$c_i$的最小值.

题解: emm.入门操作.beginner出这个题还是很不错的.

#include <bits/stdc++.h>
using namespace std;

#define MAX_N 105
int N,T;

int main(){
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0); cin.tie(0);
    int c,t;
    while(cin >> N >> T){
        int ans = INT_MAX;
        for(int i = 1; i <= N; ++i){
            cin >> c >> t;
            if(t <= T) ans = min(ans, c);
        }
        if(ans == INT_MAX) cout << "TLE" << endl;
        else cout << ans << endl;
    }
	return 0;
}

C - Pyramid

WA

ps: 到最后没做出这道题.想暴力.然后看到

The center coordinates and the height of the pyramid can be uniquely identified

这句话.理解成中心点的坐标和h可能是无穷的.orz 应该是: 可以唯一地识别金字塔的中心坐标和高度. by google translate

题目大意: 有N个点.$(x_i, y_i,h_i)$. $h_i$表示这个点的高度.求一个点$(C_x, C_y, H)$满足. $h_i = max(H-|x_i - C_x| + |y_i - C_y|, 0)$.

题解: 由于$0 <= C_x, C_y <= 100.$所以暴力即可.

#include <bits/stdc++.h>
using namespace std;



#define MAX_N 110
int n;
int x[MAX_N], y[MAX_N], h[MAX_N];

int main(){
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0); cin.tie(0);
    while(cin >> n){
        for(int i = 1; i <= n; ++i){
            cin >> x[i] >> y[i] >> h[i];
            if(h[i] > 0) {
                swap(h[i], h[1]);
                swap(x[i], x[1]);
                swap(y[i], y[1]);
            }
        }
        for(int cx = 0; cx <= 100; ++cx){
            for(int cy = 0; cy <= 100; ++cy){
                int ch = h[1] + abs(x[1] - cx) + abs(y[1] - cy);
                bool is = true;
                for(int i = 2; i <= n; ++i){
                    if(max(ch - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]) {
                        is = false;
                        break;
                    }
                }
                if(is){
                    cout << cx << " " << cy << " " << ch << endl;
                    return 0;
                }
            }
        }
    }
	return 0;
}

D - Partition

AC

题目大意: 两个数N,M.可以有多种方案找N个数之和是M.每种方案N个数的最大公约数是x.这多种方案中x最大 $$ \sum_{i=1}^{N}a_i = M $$ $$ ans = max(gcd(a_1, a_2,…,a_N))$$

题解: 可以确定.答案不超过M/N.如果答案是x.那么.这个N个数一定是x的倍数.所以只要从M/N到1枚举.第一个满足 M每次减去x的k倍.最后如果M是0.说明当前x是答案.因为是从大到小枚举.所以第一个肯定是最大的.

#include <bits/stdc++.h>
using namespace std;

#define MAX_N 105
int N,M;

bool can(int x){
    int m = M;
    m -= x;
    while(m > 0 && m/x){
        m -= (m/x * x);
    }
    return m == 0;
}

int main(){
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0); cin.tie(0);
    while(cin >> N >> M){
        for(int ans = M/N; ans >= 1; --ans){
            if(can(ans)) {
                cout << ans << endl;
                break;
            }
        }
    }
	return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-10-062,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • A - Programming Education
  • B - Time Limit Exceeded
  • C - Pyramid
  • D - Partition
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档