AcWing 4497. 分糖果
输入样例:
4 1 3 4 1 10 100 10000000000000000 10000000000000000 10000000000000000 23 34 45
输出样例:
4 55 15000000000000000 51
#include <iostream>
using namespace std;
typedef long long LL;
int main()
{
int T; cin >> T;
while(T -- )
{
LL a, b, c;
cin >> a >> b >> c;
cout << (a + b + c) / 2 << endl;
}
return 0;
}
AcWing 4498. 指针
输入样例1:
3 10 20 30
输出样例1:
YES
输入样例2:
3 10 10 10
输出样例2:
NO
输入样例3:
3 120 120 120
输出样例3:
YES
采用二进制枚举的方式来遍历所有的情况,最后进行判断
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 20;
int n;
int w[N];
int main()
{
cin >> n;
for(int i = 0; i <n; i ++ ) cin >> w[i];
bool res = false;
for(int i = 0; i < 1 << n; i ++ )
{
int s = 0;
for(int j = 0; j < n; j ++ )
if(i >> j & 1)
s += w[j];
else
s -= w[j];
if(s % 360 == 0)
{
res = true;
break;
}
}
if(res) puts("YES");
else puts("NO");
return 0;
}
AcWing 4499. 画圆
输入样例1:
5 3 3 1 1
输出样例1:
3.767767 3.767767 3.914214
输入样例2:
10 5 5 5 15
输出样例2:
5.000000 5.000000 10.000000
题目所给的三个要求为以下含义:
- 新的圆要在给定的圆内
- 给定坐标的点要在圆外
- 新的圆要求面积最大
情况1:若给定坐标的点在圆外
答案就是给定的圆
情况2:若给定坐标的点在圆内
答案就是给定点和圆心相连(延长线)所得到的最大圆
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const double eps = 1e-8;
int cmp(double x, double y)
{
if(fabs(x - y) < eps) return 0;
if(x < y) return -1;
return 1;
}
int main()
{
double r, x1, y1, x2, y2;
cin >> r >> x1 >> y1 >> x2 >> y2;
double dx = x1 - x2;
double dy = y1 - y2;
double d = sqrt(dx * dx + dy * dy);
if(cmp(d, r) >= 0) printf("%lf %lf %lf\n", x1, y1, r);
else
{
if(!cmp(x1, x2) && !cmp(y1, y2))
printf("%lf %lf %lf\n", x1 + r / 2, y1, r / 2);
else
{
double r2 = (r + d) / 2;
double x = x2 + (x1 - x2) / d * r2;
double y = y2 + (y1 - y2) / d * r2;
printf("%lf %lf %lf\n", x, y, r2);
}
}
return 0;
}