B, ground beef clan match
In fact, one-third of the board should be regarded as a main topic.
#include <iostream> #include <algorithm> #include <string> #include <string.h> #include <vector> #include <map> #include <stack> #include <set> #include <queue> #include <math.h> #include <cstdio> #include <iomanip> #include <time.h> #include <bitset> #define LL long long #define INF 0x3f3f3f3f #define ls nod<<1 #define rs (nod<<1)+1 #define PI acos(-1) const double eps = 1e-9; const int maxn = 1e5 + 10; using namespace std; struct point { int x,y; }p[maxn]; int n; double f(double x) { double max = 0; for (int i = 1;i <= n;i++) { double temp = sqrt(p[i].y*p[i].y+(p[i].x-x)*(p[i].x-x)); if (temp > max) max = temp; } return max; } int main () { scanf("%d",&n); for (int i = 1;i <= n;i++) scanf("%d%d",&p[i].x,&p[i].y); double l = -10000,r = 10000; while (l + eps < r) { double m1 = l + (r-l) / 3; double m2 = r - (r-l) / 3; if (f(m1) > f(m2)) l = m1; else r = m2; } printf("%.4lf\n",f(l)); return 0; }
D, and beef cattle sister appointments
Inside the first thing to note STL pow (a, b) function does not handle the case where a negative.
greedy. Compare and go directly to a flash which can go faster, select the faster way to go to.
#include <iostream> #include <algorithm> #include <string> #include <string.h> #include <vector> #include <map> #include <stack> #include <set> #include <queue> #include <math.h> #include <cstdio> #include <iomanip> #include <time.h> #include <bitset> #define LL long long #define INF 0x3f3f3f3f #define ls nod<<1 #define rs (nod<<1)+1 #define PI acos(-1) const double eps = 1e-9; const int maxn = 1e5 + 10; using namespace std; int main() { int T; scanf("%d",&T); while (T--) { double a,b; scanf("%lf%lf",&a,&b); double ans = 0.0; double p = 1.0 / 3.0; while (1) { double temp; if (a < 0) temp = -pow(-a,p); else temp = pow(a,p); if (abs(temp-b)+1.0 < abs(a-b)) { years + = 1.0 ; a = temp; } else { ans += abs(a-b); break; } } printf("%.9lf\n",ans); } return 0; }
F, annoying chatters
#include <iostream> #include <algorithm> #include <string> #include <string.h> #include <vector> #include <map> #include <stack> #include <set> #include <queue> #include <math.h> #include <cstdio> #include <iomanip> #include <time.h> #include <bitset> #define LL long long #define INF 0x3f3f3f3f #define ls nod<<1 #define rs (nod<<1)+1 #define PI acos(-1) const double eps = 1e-9; const int maxn = 1e5 + 10; const LL mod = 1e9 + 7; using namespace std; LL dp[maxn][3]; int main() { int x,q; cin >> x >> q; dp[0][0] = 1; for (int i = 1;i < maxn;i++) { dp[i][0] = (dp[i-1][0] + dp[i-1][1])%mod; if (i >= x ) dp[i][1] = dp[i-x][0] % mod; } dp[1][2] = dp[1][0] + dp[1][1]; for (int i = 2;i < maxn;i++) { dp[i][2] = (dp[i-1][2] + dp[i][0] + dp[i][1] ) % mod; } while (q--) { int l,r; cin >> l >> r; LL ans = dp[r][2] - dp[l-1][2]; cout << (ans + mod) % mod << endl; } return 0; }
G, arcade hegemony
First, look at the mobile zombie, easily find the mobile zombie period is 2 * (k-1), so it will need to record a three-dimensional array inside which 2 * (k-1) the time position of zombies
Other words on ordinary bfs no difference
#include <iostream> #include <algorithm> #include <string> #include <string.h> #include <vector> #include <map> #include <stack> #include <set> #include <queue> #include <math.h> #include <cstdio> #include <iomanip> #include <time.h> #include <bitset> #define LL long long #define INF 0x3f3f3f3f #define ls nod<<1 #define rs (nod<<1)+1 #define PI acos(-1) const double eps = 1e-9; const int maxn = 600; const LL mod = 1e9 + 7; using namespace std; int n,m,p,k; int vis[maxn][maxn]; int T[maxn][maxn][20]; char s[maxn][maxn]; int dir[4][2] = {{0,1},{0,-1},{-1,0},{1,0}}; int ex,ey,sx,sy; struct node { int x,y; int cnt; }; bool check(int x,int y,int tim) { if (vis[x][y] || x <= 0 || x > n || y <= 0 || y > m || s[x][y] == '&') return true; if (T[x][y][tim % (2 * k - 2)]) return true; return false; } you BFS ( you get, you y) { queue<node> q; q.push({x,y,0}); vis[x][y] = 1; while (!q.empty()) { node now = q.front(); q.pop(); if (now.x == ex && now.y == ey) return now.cnt; for (int i = 0;i < 4;i++) { int xx = now.x + dir[i][0]; int yy = now.y + dir[i][1]; if (check(xx,yy,now.cnt+1)) continue; vis[xx][yy] = 1; q.push({xx,yy,now.cnt+1}); } } return -1; } int main () { cin >> n >> m >> p >> k; getchar(); for (int i = 1;i <= n;i++) { scanf("%s",s[i]+1); for (int j = 1;j <= m;j++) { if (s[i][j] == 'L') { sx = i; and = j; } if (s[i][j] == 'A') { ex = i; ey = j; } } } for (int i = 1;i <= p;i++) { char str[10]; int x,y; cin >> x >> y; cin >> str; T[x][y][0] = T[x][y][2*k-2] = 1; if (str[0] == 'R') { for (int j = 1;j < k;j++) { x = x + dir [ 0 ] [ 0 ]; and = y + dir [ 0 ] [ 1 ]; T[x][y][j] = T[x][y][2*k-2-j] = 1; } } if (str[0] == 'L') { for (int j = 1;j < k;j++) { x = x + dir [ 1 ] [ 0 ]; and = y + dir [ 1 ] [ 1 ]; T[x][y][j] = T[x][y][2*k-2-j] = 1; } } if (str[0] == 'U') { for (int j = 1;j < k;j++) { x = x + dir [ 2 ] [ 0 ]; and = y + dir [ 2 ] [ 1 ]; T[x][y][j] = T[x][y][2*k-2-j] = 1; } } if (str[0] == 'D') { for (int j = 1;j < k;j++) { x = x + dir [ 3 ] [ 0 ]; and = y + dir [ 3 ] [ 1 ]; T[x][y][j] = T[x][y][2*k-2-j] = 1; } } } int years = bfs (sx, sy); if (age == - 1 ) cout << "Oh no" << endl; else cout << ans << endl; }
H、hash
To observe the hash function can easily be seen, this is just a hash function to a string consisting only of lowercase characters 26 as a hexadecimal number, modulo not the case, and a lowercase string arbitrary natural numbers It is one to one. Thus, as long as the character string to convert into a corresponding binary integer 26, the analog to digital converter coupled back to a string, the string will be able to obtain a minimum lexicographically larger than the original string. As long as the new string length of string 6 that is required to meet.
#include <iostream> #include <algorithm> #include <string> #include <string.h> #include <vector> #include <map> #include <stack> #include <set> #include <queue> #include <math.h> #include <cstdio> #include <iomanip> #include <time.h> #include <bitset> #define LL long long #define INF 0x3f3f3f3f #define ls nod<<1 #define rs (nod<<1)+1 #define PI acos(-1) const double eps = 1e-8; const int maxn = 1e5 + 10; using namespace std; char str[15]; int mod; int main() { while (~scanf("%s%d",str,&mod)) { LL res = 0; for (int i = 0;i < 6;i++) res = res * 26 + str[i] - 'a'; res += mod; for (int i = 5;i >= 0;i--) { str[i] = res % 26 + 'a'; res /= 26; } if (res) printf("-1\n"); else { printf("%s\n",str); } } return 0; }