C - Cardboard Containerhttps://vjudge.net/problem/Kattis-cardboardcontainer
c题是给定n个 棱长为1的立方体,来摆成一大的长方体(包括正方体),求所有可能摆成的长方体的表面积最小值。
暴力枚举其中两条边,计算出第三条边(因为最小单位是1,所以必须整除)
#include <iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<math.h>
#include<map>
#define TLE std::ios::sync_with_stdio(false)
using namespace std;
typedef pair<int, int>pii;
typedef pair<int,pii>PII;
const int INF = 0x3f3f3f3f;
const int N = 5e5 + 10;
int ans = INF;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= sqrt(n); i++)//枚举道sqrt(n)即可
{
for (int j = 1; j <= i; j++)
{
if (n % (i * j) == 0)
{
int k = n / (i * j);
ans = min(ans, 2 * (i * j + i * k + k * j));
}
}
}
cout << ans;
return 0;
}
J - Janitor Troubleshttps://vjudge.net/problem/Kattis-janitortroubles
已知四边形四条边求四边形最大面积的问题根据海伦公式求即可
#include<bits/stdc++.h>
using namespace std;
int main()
{
double a, b, c, d;
cin >> a >> b >> c >> d;
double p = (a + b + c + d) / 2;
printf("%.15f\n", sqrt((p - a) * (p - b) * (p - c) * (p - d)));
return 0;
}
F - Financial Planninghttps://vjudge.net/problem/Kattis-financialplanning
二分答案+贪心,注意INF要开1e9*10,0x3f3f3f3f是wa的
#include<bits/stdc++.h>
#define TLE ios::sync_with_stdio(0);
using namespace std;
typedef long long ll;
const int INF = 1e9 * 10;
const int N = 1e5 + 100;
ll n, m;
struct node
{
ll v, w;
}a[N];
bool check(ll x)
{
ll now=0;
for (int i = 1; i <= n; i++)
{
if (a[i].v * x- a[i].w >0 )
{
now += a[i].v * x - a[i].w;
if (now >= m)return true;
}
}
return false;
}
int main()
{
TLE;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i].v >> a[i].w;
}
ll l = 0, r = INF;
ll ans = 0;
while (l < r)
{
ll mid = (l + r)/2;
if (check(mid))r = mid;
else l = mid+1;
}
cout << r << endl;
return 0;
}
g题未完待续