C
差分,前缀和
AC代码:
/* Tips: 1.int? long long? 2.don't submit wrong answer 3.figure out logic first, then start writing please 4.know about the range 5.check if you have to input t or not 6.modulo of negative numbers is not a%b, it is a%b + abs(b) */ #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x) & -(x)) #define endl '\n' #define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef vector<int> vi; typedef vector<long long> vll; typedef vector<char> vc; typedef long long ll; template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<class T> T power(T a, int b) { T res = 1; for (; b; b >>= 1, a = a * a) { if (b & 1) { res = res * a; } } return res; } template <typename T> inline void read(T& x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); } x *= f; } const int INF = 0x3f3f3f3f; const int mod = 1000000007; const double PI = acos(-1.0); const double eps = 1e-6; inline int sgn(double x) { return x < -eps ? -1 : x > eps; } char s[100010]; int b[200010], r[200010], ans; void solve() { int n, t, a; cin >> n >> t; scanf("%s", s + 1); for (int i = 1; i <= n; i++) { cin >> a; if (s[i] == 'B') { b[a]++; b[a + t]--; } else { r[a]++; r[a + t]--; } } for (int i = 1; i <= 200000; i++) { r[i] += r[i - 1]; b[i] += b[i - 1]; } for (int i = 1; i <= 200000; i++) { if (b[i] && !r[i]) { ans++; } } cout << ans << endl; return; } int main() { //IOS1; //IOS2; int __t = 1; // cin >> __t; for (int _t = 1; _t <= __t; _t++) { solve(); } return 0; } /* */
E
f函数是在模拟二进制,输入输出
AC代码:
/* Tips: 1.int? long long? 2.don't submit wrong answer 3.figure out logic first, then start writing please 4.know about the range 5.check if you have to input t or not 6.modulo of negative numbers is not a%b, it is a%b + abs(b) */ #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include <iostream> #include <queue> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <cctype> #include <map> #include <vector> #include <deque> #include <set> #include <stack> #include <numeric> #include <iomanip> #include <functional> using namespace std; #define lowbit(x) ((x) & -(x)) #define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef vector<int> vi; typedef vector<long long> vll; typedef vector<char> vc; typedef long long ll; template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<class T> T power(T a, int b) { T res = 1; for (; b; b >>= 1, a = a * a) { if (b & 1) { res = res * a; } } return res; } template <typename T> inline void read(T& x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); } x *= f; } const int INF = 0x3f3f3f3f; const int mod = 1000000007; const double PI = acos(-1.0); const double eps = 1e-6; inline int sgn(double x) { return x < -eps ? -1 : x > eps; } //计算几何 //向量 //struct Point { // double x, y; // Point operator - (Point a) {//向量加法 // return { x - a.x,y - a.y }; // } // Point operator + (Point a) {//向量减法 // return { x + a.x,y + a.y }; // } // double operator * (Point a) {//点乘 // return x * a.x + y * a.y; // } // double operator % (Point a) {//叉乘 // return x * a.y - y * a.x; // } // bool operator == (Point a) {//两点是否重合 // return !sgn(x - a.x) && !sgn(y - a.y); // } // long double len() {//返回向量的模 // return hypot(x, y); // } // Point rot(long double arg) {//向量旋转 // long double Cos = cos(arg), Sin = sin(arg); // return { x * Cos - y * Sin,x * Sin + y * Cos }; // } //}; //直线 or 射线 //struct Line { // Line() {} // Line (Point s,Point e): s(s),e(s){} // Point s, e; //}; void solve() { long long x; cin >> x; cout << x << endl; } int main() { IOS1; //IOS2; int __t = 1; //cin >> __t; for (int _t = 1; _t <= __t; _t++) { solve(); } return 0; } /* */
F
模拟
AC代码:
/* Tips: 1.int? long long? 2.don't submit wrong answer 3.figure out logic first, then start writing please 4.know about the range 5.check if you have to input t or not 6.modulo of negative numbers is not a%b, it is a%b + abs(b) */ #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include <iostream> #include <queue> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <cctype> #include <map> #include <vector> #include <deque> #include <set> #include <stack> #include <numeric> #include <iomanip> #include <functional> using namespace std; #define lowbit(x) ((x) & -(x)) #define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef vector<int> vi; typedef vector<long long> vll; typedef vector<char> vc; typedef long long ll; template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<class T> T power(T a, int b) { T res = 1; for (; b; b >>= 1, a = a * a) { if (b & 1) { res = res * a; } } return res; } template <typename T> inline void read(T& x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); } x *= f; } const int INF = 0x3f3f3f3f; const int mod = 1000000007; const double PI = acos(-1.0); const double eps = 1e-6; inline int sgn(double x) { return x < -eps ? -1 : x > eps; } //计算几何 //向量 //struct Point { // double x, y; // Point operator - (Point a) {//向量加法 // return { x - a.x,y - a.y }; // } // Point operator + (Point a) {//向量减法 // return { x + a.x,y + a.y }; // } // double operator * (Point a) {//点乘 // return x * a.x + y * a.y; // } // double operator % (Point a) {//叉乘 // return x * a.y - y * a.x; // } // bool operator == (Point a) {//两点是否重合 // return !sgn(x - a.x) && !sgn(y - a.y); // } // long double len() {//返回向量的模 // return hypot(x, y); // } // Point rot(long double arg) {//向量旋转 // long double Cos = cos(arg), Sin = sin(arg); // return { x * Cos - y * Sin,x * Sin + y * Cos }; // } //}; //直线 or 射线 //struct Line { // Line() {} // Line (Point s,Point e): s(s),e(s){} // Point s, e; //}; void solve() { string s; cin >> s; string ans = ""; int len = s.size(); bool ok1 = false, ok2 = false; int cnt1 = 0, cnt2 = 0; for (int i = 0; i < len; i++) { if (s[i] == 'C') { ans += '1'; if (ok1) { for (int j = 0; j < cnt1; j++) { ans += '.'; } } if (ok2) { for (int j = 0; j < cnt2; j++) { ans += '*'; } } } else if (s[i] == 'D') { ans += '2'; if (ok1) { for (int j = 0; j < cnt1; j++) { ans += '.'; } } if (ok2) { for (int j = 0; j < cnt2; j++) { ans += '*'; } } } else if (s[i] == 'E') { ans += '3'; if (ok1) { for (int j = 0; j < cnt1; j++) { ans += '.'; } } if (ok2) { for (int j = 0; j < cnt2; j++) { ans += '*'; } } } else if (s[i] == 'F') { ans += '4'; if (ok1) { for (int j = 0; j < cnt1; j++) { ans += '.'; } } if (ok2) { for (int j = 0; j < cnt2; j++) { ans += '*'; } } } else if (s[i] == 'G') { ans += '5'; if (ok1) { for (int j = 0; j < cnt1; j++) { ans += '.'; } } if (ok2) { for (int j = 0; j < cnt2; j++) { ans += '*'; } } } else if (s[i] == 'A') { ans += '6'; if (ok1) { for (int j = 0; j < cnt1; j++) { ans += '.'; } } if (ok2) { for (int j = 0; j < cnt2; j++) { ans += '*'; } } } else if (s[i] == 'B') { ans += '7'; if (ok1) { for (int j = 0; j < cnt1; j++) { ans += '.'; } } if (ok2) { for (int j = 0; j < cnt2; j++) { ans += '*'; } } } else if (s[i] == '<') { if (!ok2) { cnt1++; ok1 = true; } else { cnt2--; if (cnt2 == 0) { ok2 = false; } } } else if (s[i] == '>') { if (!ok1) { ok2 = true; cnt2++; } else { cnt1--; if (cnt1 == 0) { ok1 = false; } } } } cout << ans << endl; } int main() { IOS1; //IOS2; int __t = 1; //cin >> __t; for (int _t = 1; _t <= __t; _t++) { solve(); } return 0; } /* */
H
紫希望尽可能地近,红希望尽可能地远,贪心一下可以知道紫最佳就是坐在对角线的交点,那么红必须坐在八个角上,立体几何算一算即可
AC代码:
/* Tips: 1.int? long long? 2.don't submit wrong answer 3.figure out logic first, then start writing please 4.know about the range 5.check if you have to input t or not 6.modulo of negative numbers is not a%b, it is a%b + abs(b) */ #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include <iostream> #include <queue> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <cctype> #include <map> #include <vector> #include <deque> #include <set> #include <stack> #include <numeric> #include <iomanip> #include <functional> using namespace std; #define lowbit(x) ((x) & -(x)) #define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef vector<int> vi; typedef vector<long long> vll; typedef vector<char> vc; typedef long long ll; template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<class T> T power(T a, int b) { T res = 1; for (; b; b >>= 1, a = a * a) { if (b & 1) { res = res * a; } } return res; } template <typename T> inline void read(T& x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); } x *= f; } const int INF = 0x3f3f3f3f; const int mod = 1000000007; const double PI = acos(-1.0); const double eps = 1e-6; inline int sgn(double x) { return x < -eps ? -1 : x > eps; } //计算几何 //向量 //struct Point { // double x, y; // Point operator - (Point a) {//向量加法 // return { x - a.x,y - a.y }; // } // Point operator + (Point a) {//向量减法 // return { x + a.x,y + a.y }; // } // double operator * (Point a) {//点乘 // return x * a.x + y * a.y; // } // double operator % (Point a) {//叉乘 // return x * a.y - y * a.x; // } // bool operator == (Point a) {//两点是否重合 // return !sgn(x - a.x) && !sgn(y - a.y); // } // long double len() {//返回向量的模 // return hypot(x, y); // } // Point rot(long double arg) {//向量旋转 // long double Cos = cos(arg), Sin = sin(arg); // return { x * Cos - y * Sin,x * Sin + y * Cos }; // } //}; //直线 or 射线 //struct Line { // Line() {} // Line (Point s,Point e): s(s),e(s){} // Point s, e; //}; void solve() { int x; cin >> x; double ans; ans = 1.0 * x * 2 / sqrt(3); cout << fixed << setprecision(7) << ans * ans * ans << endl; } int main() { IOS1; //IOS2; int __t = 1; //cin >> __t; for (int _t = 1; _t <= __t; _t++) { solve(); } return 0; } /* */
K
找到第一个大于x的2的幂次,然后x+2的幂次*x=2的幂次+1倍的x
AC代码:
/* Tips: 1.int? long long? 2.don't submit wrong answer 3.figure out logic first, then start writing please 4.know about the range 5.check if you have to input t or not 6.modulo of negative numbers is not a%b, it is a%b + abs(b) */ #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include <iostream> #include <queue> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <cctype> #include <map> #include <vector> #include <deque> #include <set> #include <stack> #include <numeric> #include <iomanip> #include <functional> using namespace std; #define lowbit(x) ((x) & -(x)) #define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef vector<int> vi; typedef vector<long long> vll; typedef vector<char> vc; typedef long long ll; template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<class T> T power(T a, int b) { T res = 1; for (; b; b >>= 1, a = a * a) { if (b & 1) { res = res * a; } } return res; } template <typename T> inline void read(T& x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); } x *= f; } const int INF = 0x3f3f3f3f; const int mod = 1000000007; const double PI = acos(-1.0); const double eps = 1e-6; inline int sgn(double x) { return x < -eps ? -1 : x > eps; } int a[40]; void init() { a[0] = 1; long long x = 2; for (int i = 1; i <= 31; i++,x *= 2) { a[i] = x; } } void solve() { long long x; cin >> x; long long ans = x; int sign = 0; for (int i = 0; i <= 31; i++) { if (x < a[i]) { sign = i; break; } } for(int i = 0;i < sign;i++){ x <<= 1; } cout << x + ans << endl; } int main() { IOS1; //IOS2; init(); int __t = 1; //cin >> __t; for (int _t = 1; _t <= __t; _t++) { solve(); } return 0; } /* */
2022牛客寒假算法基础集训营4(5/12)
于 2022-02-15 14:43:38 首次发布