hpu集训一场

比赛链接

A 解方程
这个题目用的是一个浮点数二分来进行计算。这道题目我错了很多次。** 原因是我平常使用的取消同步流**这个东西scanf 和 cin printf 和 cout 是不能同时用的。
所以以后全用 scanf 和 printf 就行了。
代码如下:精度超级高(哈哈,考试的时候错了 20 次)

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

double get(double m)
{
    return 2018.0 * pow(m, 4) + 21.0 * m + 5.0 * pow(m, 3) + 5.0 * pow(m, 2) + 14.0;
}

void solve()
{
    double y; cin >> y;
    if (y < 14.0 || y > get(100.0))
    {
        cout << -1 << "\n";
        return ;
    }
    double l = 0.0, r = 100.0;
    while (r - l > 1e-12)
    {
        double m = (l + r) / 2.0;
        if (get(m) >= y)
        r = m;
        else l = m;
    }
    double ans = (l + r) / 2;
    printf("%.4lf\n", ans);
}

int main()
{
	// ios::sync_with_stdio(false);
	// cin.tie(nullptr);
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

B MC真好玩
这个题目首先考虑 x 是 y 的二倍或者 y 是 x 的二倍的情况。
然后如果都不是那就让他们加起来 / 3 ,可以把这两个木根和钻石看成一种就行。

    int x, y;
    scanf("%d%d", &x, &y);
    if (2 * x <= y)
    {
        cout << x << "\n";
        return ;
    }
    if (2 * y <= x)
    {
        cout << y << "\n";
        return ;
    }
    cout << (x + y) / 3 << "\n";

C 竞赛技巧
全部转化为秒,然后排序之后输出即可。

    int n; cin >> n;
   int h, m, ss;
   vector<int> a(n);
   for (int i = 0; i < n; i ++)
   {
       cin >> h >> m >> ss;
//         cout << h << " " << m << " " << ss << "\n";
       a[i] = h * 3600 + m * 60 + ss;
   }
   sort(a.begin(), a.end());
   for (int i = 0; i < n; i ++)
   {
       printf("%d %d %d\n", a[i] / 3600, a[i] % 3600 / 60, a[i] % 60);
   }

E 数圈圈
4 6 9 0 是一个圈
8 是两个圈,看各个位置上的数即可。

int get(int x)
{
    int ans = 0;
    while (x)
    {
        int u = x % 10;
        if (u == 4 || u == 6 || u == 9 || u == 0) ans += 1;
        if (u == 8) ans += 2;
        x /= 10;
    }
    return ans;
}
 
void solve()
{
    int a, b; cin >> a >> b;
    int res = 0;
    for (int i = a; i <= b; i ++)
    {
        res += get(i);
    }
    cout << res << "\n";
}

G 投票统计
这个题目要存一下投票给的题目编号。用map 存一下,后续遍历一下。然后记录投票数的最大值。


void solve()
{
    map<int, int> cnt;
    cin >> n;
    int mmax = -1;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        cnt[x]++;
        mmax = max(mmax, cnt[x]);
    }
    vector<int> id;
    for (auto &u : cnt)
    {
        id.push_back(u.first);
    }
    sort(id.begin(), id.end());
    int len = id.size();
    // for (int i = 0; i < len; i ++)
    // {
    //     cout << id[i] << " ";
    // }
    // cout << "\n";
    // printf("mmax = %d\n", mmax);
    int u = 0;
    for (int i = 0; i < len; i ++)
    {
        if (cnt[id[i]] == mmax)
        {
            u ++;
        }
    }
    if (u == id.size())
    {
        printf("-1\n");
        return ;
    }
    else 
    {
        cout << u << "\n";
        for (int i = 0; i < len; i ++)
        {
            if (cnt[id[i]] == mmax)
            {
                cout << id[i] << " ";
            }
        }
    }
    cout << "\n";
}

牛牛玩平板
这个题倒着操作即可。看一下样例。

void solve()
{
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i ++) cin >> a[i];
    sort(a.begin(), a.end());
    i64 ans = 0;
    // int sum = a[0];
    for (int i = n - 1; i >= 1; i --)
    {
        ans += a[i] * a[i - 1];
        // cout << ans << "\n";
        a[i - 1] = a[i] + a[i - 1];
    }

    cout << ans << "\n";
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值