寒假限时训练(1)G、 H、 I

· · 个人记录

G - New Year Candles

#include <iostream>
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    int res=n;
    while(n>=m)//如果当前的用过的蜡烛还可以变成新的
    {
       int t=n/m;
       res+=t;
       n=n%m+t;//用过的蜡烛等于新用完的加上之前没用的
    }
    cout << res;
    return 0;
}

H - Fancy Fence

正多边型的外角都相等

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int a;
        cin >> a;
        if (360 % (180-a) == 0)
        {
            cout << "YES" << endl;
        }
        else
            cout << "NO" << endl;
    }
    return 0;
}

I - Board Moves

思路:在中点处,向外每一层需要的步数加一,步数乘这一乘的方块数

#include <iostream>
using namespace std;
#define ll long long
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        ll ans = 0;
        n /= 2;
        for (int i = 1; i <= n; i++)
        {
            ans += (ll)i * 8 * i;//这里要强制类型转换,i*8*i 会直接爆int
        }
        cout << ans << endl;
    }
    return 0;
}