洛谷题库链接
T1
题目链接
想要严格证明可能有点困难,但是可以猜。设原点为A,终点为B,从A一直向右走,走和AB长度相等的距离点C后使用一次圆周移动到达点B,最后形成的图形是一个扇形,答案就是AC+CB(弧长)。就算过程中需要用到C++数学库里的atan函数,最后要四舍五入。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include <bits/stdc++.h> using namespace std;#define endl '\n' #define IO ios::sync_with_stdio(0); cin.tie(0); typedef long long ls;const int N = 1e5 + 10 ;const double eps = 1e-5 ;void sol () { double l = sqrt (233 *233 +666 *666 ); double a = atan (666.0 /233 ); cout << (ls)(a*l+l) << endl; } int main () { IO; sol (); }
*T2
题目链接
这题实际上是一道trick题目,如果没有发现规律的话可以使用暴力枚举看看哪些数是满足条件的(必会的操作)。枚举出来之后就可以发现,除了1不满足,其余的数都满足条件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #include <bits/stdc++.h> using namespace std;#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); typedef long long ls;typedef unsigned long long uls;#define endl '\n' const int N = 1e5 + 10 ;const int M = 1e3 + 10 ;void sol () { int n; cin >> n; int cnt = 0 ; for (int i = 1 ; i<= n; i++) { int x; cin >> x; if (x != 1 ) cnt++; } cout << cnt << endl; } int main () { IO; sol (); }
*T3
题目链接
取平均的操作会使数组的极差变得越来越小 ,直到为 0,使得 a =b =c ,这时题目中的三个操作均无法影响到这三个数的值,所以在 a =b =c 时直接退出即可(其实也可以限制一下循环的次数100次,也可以AC)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #include <bits/stdc++.h> using namespace std;#define endl '\n' #define IO ios::sync_with_stdio(0); cin.tie(0); typedef long long ls;const int N = 1e5 + 10 ;const double eps = 1e-5 ;void sol () { int a, b, c, k; cin >> a >> b >> c >> k; if (k > 100 ) k = 100 ; while (k--){ int aa = (b+c)/2 ; int bb = (a+c)/2 ; int cc = (a+b)/2 ; a = aa, b = bb, c = cc; } cout << a << ' ' << b << ' ' << c << endl; } int main () { IO; int k; cin >> k; while (k--) sol (); }
*T4
题目链接
中学老师就教过我们,看到绝对值优先去绝对值,排个序即可。随后展开求和的表达式就会发现,题目其实是让我们在单调序列里找所有长度为m滑动窗口内最大值平方与最小值平方差的最小值。计算平方时候记得乘上1LL。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #include <bits/stdc++.h> using namespace std;#define endl '\n' #define IO ios::sync_with_stdio(0); cin.tie(0); typedef long long ls;const int N = 1e6 + 10 ;const int M = 60 ;ls a[N]; void sol () { int n, m; cin >> n >> m; for (int i = 1 ; i <= n; i++) cin >> a[i]; sort (a + 1 , a + n + 1 ); int t = m; for (int i = m; i <= n; i++) if (1LL *a[i]*a[i]-a[i-m+1 ]*a[i-m+1 ]<1LL *a[t]*a[t]-a[t-m+1 ]*a[t-m+1 ]) t = i; cout << 1LL *a[t]*a[t]-a[t-m+1 ]*a[t-m+1 ] << endl; } int main () { sol (); }
T5
题目链接
模拟题,仔细琢磨琢磨。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 #include <bits/stdc++.h> using namespace std;#define endl '\n' #define IO ios::sync_with_stdio(0); cin.tie(0); typedef long long ls;const int N = 1e6 + 10 ;const int M = 60 ;string s[2 ]; struct zh { int t; bool a, b; }; void sol () { cin >> s[0 ] >> s[1 ]; vector<zh> arr; for (int i = 0 ; i < (int )s[0 ].size (); i++){ if (s[0 ][i] == '#' && s[1 ][i] == '#' ) arr.push_back ({i, 1 , 1 }); else if (s[0 ][i] == '#' ) arr.push_back ({i, 1 , 0 }); else if (s[1 ][i] == '#' ) arr.push_back ({i, 0 , 1 }); } int cnt = 0 ; for (int i = 1 ; i < (int )arr.size (); i++){ if (arr[i].a && arr[i - 1 ].a){ cnt += arr[i].t - 1 - (arr[i - 1 ].t + 1 ) + 1 ; } else if (arr[i].b && arr[i - 1 ].b){ cnt += arr[i].t - 1 - (arr[i - 1 ].t + 1 ) + 1 ; } else if (arr[i].a && arr[i - 1 ].b){ if (i + 1 < (int )arr.size () && arr[i+1 ].b){ cnt += arr[i+1 ].t - 1 - (arr[i - 1 ].t + 1 ) + 1 ; i++; } else { cnt += arr[i].t - (arr[i - 1 ].t + 1 ) + 1 ; } } else if (arr[i].b && arr[i - 1 ].a){ if (i + 1 < (int )arr.size () && arr[i+1 ].a){ cnt += arr[i+1 ].t - 1 - (arr[i - 1 ].t + 1 ) + 1 ; i++; } else { cnt += arr[i].t - (arr[i - 1 ].t + 1 ) + 1 ; } } } cout << cnt << endl; } int main () { sol (); }