A - Weird Function
题意:我们定义一个函数 f:
f(x) = x^2 + 2x + 3.
给定一个整数 t,求 f(f(f(t) + t) + f(f(t))) 的值。
这里保证答案是不大于 2×10^9 的整数。
思路:直接带公式即可
AC代码
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define xx first
#define yy second
#define sz size
typedef long long LL;
typedef pair<int , int> PII;
typedef pair<LL , LL> PLL;
const int N = 100010, INF = 0x3f3f3f3f, Mod = 1e9 + 7;
int x;
void solved()
{
cin >> x;
int a = x * x + 2 * x + 3 + x;
int b = x * x + 2 * x + 3;
int c = a * a + 2 * a + 3;
int d = b * b + 2 * b + 3;
int ans = c + d;
cout << ans * ans + 2 * ans + 3;
return ;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//int t;
//cin >> t;
while(t -- )
{
solved();
}
return 0;
}
B - Longest Segment
题意:给定平面上的N个点,第i个点的坐标为(x_i, y_i)。要找到连接这些点中两个点的最大线段长度。
思路: 考察了数学:两点距离公式(欧氏距离),直接O(n ^ 2)
AC代码
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define xx first
#define yy second
#define sz size
typedef long long LL;
typedef pair<int , int> PII;
typedef pair<LL , LL> PLL;
const int N = 110, INF = 0x3f3f3f3f, Mod = 1e9 + 7;
int n;
int x[N], y[N];
void solved()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> x[i] >> y[i];
}
double d = 0.0;
for (int i = 1; i <= n; i ++)
{
for (int j = 1; j <= n; j ++)
{
double tmp = sqrt((x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]));
d = max(d, tmp);
}
}
printf("%.6f\n", d);
return ;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//int t;
//cin >> t;
while(t -- )
{
solved();
}
return 0;
}
C - Happy New Year!
题意: 在十进制中由0和2组成的正整数中,找到第K小的整数。
思路:本质就是计算 k 的二进制表示,注意把 ’1‘ 变成 ’2‘,由于数据很大,所以得开long long
AC代码
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define xx first
#define yy second
#define sz size
typedef long long LL;
typedef pair<int , int> PII;
typedef pair<LL , LL> PLL;
const int N = 110, INF = 0x3f3f3f3f, Mod = 1e9 + 7;
LL k;
void solved()
{
cin >> k;
string tmp = "";
while(k >= 1)
{
if(k % 2 == 0)
{
tmp = '0' + tmp;
}
else
{
tmp = '2' + tmp;
}
k /= 2;
}
cout << tmp << endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//int t;
//cin >> t;
while(t -- )
{
solved();
}
return 0;
}