codeforce #165 div2

本文回顾了一次编程比赛经历,详细解析了三个题目的解决思路与代码实现,包括判断角度能否构成正多边形的算法、确定更新板块数量的逻辑以及如何高效存储不同尺寸的魔法盒子。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这次做的不够理想,过程磕磕绊绊,C题还是倒在第42个样例上(看了下WA的人,就数我最悲剧)......


A题:求所给角度(0--180)能否组成正多边形.。

套用内角公式(n - 2)* 180 / n ,则

a == 180.0 - (360.0/j)

j为边数


#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    double a;
    while(cin >> n)
    {
        for(int i=0; i<n; i++)
        {
            cin >> a;
            int ok = 0;
            for(int j=2; j<=360; j++)
            {
                if(a == 180.0 - (360.0/j))
                {
                    ok = 1;
                    break;
                }
            }
            if(ok == 1)
            {
                cout << "YES" << endl;
            }
            else
                cout << "NO" << endl;
        }
    }
    return 0;
}


B题:

原先有一系列板块编号1-n,如有某个板块更新信息则占据首位,其他后移。给出刷新后位置由前到后的板块编号,问一定更新信息的板块有几个。


相邻两个板块i,i+1如果编号i > 编号i+1。说明板块i一定更新了,板块i+1却不一定。而板块i更新,排在板块i前面的,也是必定更新了。

这样问题就变成找最后一个满足板块编号i > 编号i+1的。


#include <iostream>
#include <cstdio>

using namespace std;

int a[100005];

int main()
{
    int n;
    while(cin >> n)
    {
        int t=0;
        for(int i=1; i<=n; i++)
        {
            cin >>  a[i];
        }
        for(int i=1; i<n; i++)
        {
            if(a[i] > a[i+1])
                t = i;
        }
        cout << t << endl;
    }
    return 0;
}


C题:

C. Magical Boxes
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.

From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure:

Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.

Input

The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 1091 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.

Output

Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.

Sample test(s)
input
2
0 3
1 5
output
3
input
1
0 4
output
1
input
2
1 10
2 2
output
3
Note

Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.

In the second test case, we can put all four small boxes into a box with side length 2.


有一堆大大小小的箱子,小的能放大的里面,求另取一个边长最短的箱子,将这些箱子装下。具体规则就看题吧...

想法是将已有箱子按照边长由小到大排序,一个循环中,将较小的放入较大些的,如果较小的剩余,则剩余的小的箱子换算成较大的;如此递推,

再枚举能装下已有最大箱子最小的边长的箱子。 虽然考虑到了k范围实在是太大了而加上if(2 * box[i+1].len - 2 * box[i].len <= 32)剔除,但没注意等于

32也是超过范围的。所以去掉等号,就行了。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

struct BOX
{
    long long len,num;
} box[100005];

bool cmp(BOX a, BOX b)
{
    return a.len < b.len;
}

int main()
{
    int n;
    while(cin >> n)
    {
        for(int i=0; i<n; i++)
        {
            cin >> box[i].len >> box[i].num;
        }
        sort(box,box+n,cmp);

        for(int i=0; i<n-1; i++)
        {
            if(2 * box[i+1].len - 2 * box[i].len < 32)
            {
                int t = ceil(box[i].num*1.0/((1 << (2*box[i+1].len -2 * box[i].len)))) - box[i+1].num;
                if(t > 0)
                    box[i+1].num += t;
            }
        }
        long long t = box[n-1].num;
        int i;
        for(i=1;; i++)
        {
            if(1 << (2 * i) >= t)
                break;
        }
        cout << i + box[n-1].len << endl;
    }
    return 0;
}


赛后发现C题是div1的第一题,可见去div1就是挂零的节奏......长路漫漫啊!!!



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值