[Codeforces] Round #287 (Div. 2) A、B

507A - Amr and Music

题意:给定一个n和k,分别代表Amr有n种乐器 和 他的最多学习天数k。接下来输入这n种乐器分别需要ai天才能学会。问Amr在这k天最多能学会的乐器数,并且把所学的乐器输出,如果答案不唯一,输出任意解。

直接结构体排序,贪心即可。

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <assert.h>
#include <time.h>
typedef long long LL;
const int INF = 500000001;
const double EPS = 1e-9;
const double PI = acos(-1.0);
using namespace std;
int n, k, ans;
struct ak
{
    int val, dis;
}s[105];
int cmp(const void *a, const void *b)
{
    struct ak c = *(struct ak *)a;
    struct ak d = *(struct ak *)b;
    return c.val - d.val;
}
int main()
{
    #ifdef _Test
        freopen("test0.in", "r", stdin);
        freopen("test0.out", "w", stdout);
        srand(time(NULL));
    #endif

    while(~scanf("%d %d", &n, &k))
    {
        ans = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%d", &s[i].val);
            s[i].dis = i;
        }
        qsort(s, n, sizeof(s[0]), cmp);
        int sum = 0;
        for(int i = 0; i < n; i++)
        {
            if(sum + s[i].val > k)
            {
                break;
            }
            sum += s[i].val;
            ans++;
        }
        printf("%d\n", ans);
        for(int i = 0; i < ans; i++)
        {
            printf(i ? " %d" : "%d", s[i].dis+1);
        }
        if(ans) puts("");
    }
    return 0;
}

507B - Amr and Pins

题意:给定一个圆的半径r和圆心(x,y),现给一个新的圆心(x', y'),现在可以在园的边界上的任意位置插入一根针,这时园可以以这个针所在的位置进行360度旋转,问最少需要几次,能将圆心变成新的位置?

由半径可知每次可以将圆心最大移动的距离2*r,那我们直接求新的圆心和以前的圆心的距离/2*r向上取整即可。注意题目爆int了。

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <assert.h>
#include <time.h>
typedef long long LL;
const int INF = 500000001;
const double EPS = 1e-9;
const double PI = acos(-1.0);
using namespace std;
double dis(LL x1, LL y1, LL x2, LL y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) *(y1 - y2));
}
int main()
{
    #ifdef _Test
        freopen("test0.in", "r", stdin);
        freopen("test0.out", "w", stdout);
        srand(time(NULL));
    #endif
    LL r, x1, y1, x2, y2;
    while(~scanf("%I64d %I64d %I64d %I64d %I64d", &r, &x1, &y1, &x2, &y2))
    {
        double k = dis(x1, y1, x2, y2);
        printf("%I64d\n", (LL)ceil(k / r / 2));
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值