Game Link: http://acm.fzu.edu.cn/contest/list.php?cid=144
problem B the perfect number
Time limit:1000 mSec Memory limit:32768 KBproblem Description
Bob is a kid who likes numbers, and now he's working on a number-related topic, and we know that the perfect degree of a number is the number of methods that divide this number into three integers multiplied by a*a*b (0<a<=b), such as the number 80 can be decomposed into 1*1*80,2*2*20, 4*5, so the perfect degree of 80 is 3; The number 5 has only one decomposition method 1*1*5, so the perfect degree is 1, assuming the digital x is the perfect degree of D (x), now given a B (a<=b), please help Bob to find out
S,s represents the sum of the prevalence of all numbers from a to B, i.e. S=d (a) +d (a+1) +...+d (b).
Inputenter two integers, a, B (1<=a<=b<=10^15)Outputoutputs an integer that represents the sum of all digital popularity from A to B. Sample Input1Sample Output107
Title analysis: Enumeration to b^ (1/3) can be, first of all, the perfect degree of a number of at least 1, because x/(i*i) (I >= 2) must be greater than I to meet A*a*b (0<a<=b), so for each possible enumeration value of the extra perfect degree of x/(i*i)-i+1
#include <cstdio> #include <cstring> #define LL long LONGLL cal (ll x) {ll cnt = 0;for (ll i = 2; I * i * I <= x ; i++) CNT + = x/(i * i)-i + 1;return x + cnt;} int main () {ll A, b;while (scanf ("%i64d%i64d", &a, &b)! = EOF) printf ("%i64d\n", Cal (b)-Cal (A-1));}
problem D hard
Time
limit:1000 mSec Memory limit:32768 KB
problem Descriptionplease convert the finite fraction to the simplest fraction. Inputan integer n indicates the number of decimal numbers to convert, and the next n lines, each line has a finite decimal. (Guaranteed number of decimal digits not exceeding 9 digits)OutputThe output has n rows, and the smallest fraction corresponding to each behavior decimalSample Input2
0.5
0.4Sample Output1/2
2/5Hintpay attention to the accuracy problem, the data guarantee will not have a decimal like 1.0.
Topic Analysis: String reading, numerator denominator with the exception of their greatest common divisor
#include <cstdio> #include <cstring> #define LL long longint const MAX = 1e5;char s[max];ll gcd (int a, int b) {RE Turn b? GCD (b, a% B): A; } int main () {int t;scanf ("%d", &t), while (t--) {scanf ("%s", s), int l = strlen (s); ll len = 1;ll num = 0;bool flag = false;f or (int i = 0; i < L; i++) {if (s[i] = = '. ') {flag = true;continue;} num = num * + (s[i]-' 0 '); if (flag) Len *= 10;} ll g = gcd (num, len);p rintf ("%i64d/%i64d\n", num/g, len/g);}}
problem F checkpoint Point
Time limit:1000 mSec Memory limit:32768 KB
problem Descriptionin a total of n sites in the mountains need to check, inspectors from the top of the station to the various sites for inspection, each site has and only one path, the inspectors down the hill to the site more relaxed, and the mountain when the need for additional time, asked the last inspector to check all the site when the minimum amount of extra time required. Inputcontains multiple sets of data for each set of data input first behavior an integer N indicates the number of sites (1<=n<=100000), followed by a line of 3 integers per line x, Y, Z (1<=z<=10000) checkpoints for the parent node of checkpoint y, X, There is a path between Y and X, which requires extra z time. (parent node above child node, peak fixed marking 1)Outputthe output line is an integer that represents the minimum amount of extra time that will be spent. Sample Input6
1 2 1
2 4 1
1 3 1
3 5 1
3 6 1Sample Output3
Title Analysis: All values minus the maximum weight from the root to the leaf path value can be
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;int Const MAX = 1e5 + 5;int r E[max], fa[max];int n;int get_num (int v) {int cnt = 0;for (; v; v = fa[v]) cnt + = Re[v];return cnt; int main () {while (scanf ("%d", &n)! = EOF) <span style= "FONT-SIZE:14PX;" >{memset (Re, 0, sizeof (RE)), memset (FA, 0, sizeof (FA)), int sum = 0;for (int i = 0; i < n-1; i++) {int u, V, w;scanf (" %d%d%d ", &u, &v, &w); Fa[v] = u;re[v] = w;sum + = W;} int ma = 0;for (int i = 2; I <= n; i++) ma = Max (MA, get_num (i));p rintf ("%d\n", Sum-ma);}} </span>
Problem G Escape
Time
limit:1000 mSec Memory limit:32768 KB
problem DescriptionXiao Ming into the underground maze to find treasures, found the treasure but there was an earthquake, the maze produced magma everywhere, Xiao Ming hurriedly fled to the exit. If you leave the treasure, Xiaoming can quickly leave the maze, but Xiao Ming does not want to easily give up his hard earned. So he hurried in contact with the programmer's friend (of course, by phone) and told you what he was facing, hoping you could tell him if he could succeed in escaping with the treasure. Input
There are multiple sets of test data.
The first line of each set of test data is an integer t, representing the number of examples to be followed. (0<=t<=10)
Next is the T-group example.
The first line of each set of examples is two integers n and M. Represents the size of the maze with N rows M column (0<=n,m<=1000).
Next is a description of the maze of n*m.
s represents the location of Xiaoming.
E for export, only one export.
. Represents a place where you can walk.
! Represents the place where magma is produced. (This place will have multiple, with a number less than or equal to 10000)
#代表迷宫中的墙, it can not only stop Xiao Ming forward can also block the spread of magma.
Xiao Ming carrier treasure can only move around one cell per second, xiaoming can not touch the magma (Xiao Ming can not and magma in the same lattice).
Magma spreads a grid every second to places that are not walls.
After Xiao Ming first move, the magma will spread to the corresponding lattice.
Xiao Ming can move to the exit, then Xiao Ming escaped smoothly.
Outputeach set of test data outputs has only one line of "Yes" or "No". "Yes" means Xiao Ming can escape successfully. Otherwise output "No". Sample Input3
5 5
....!
S ....
#....
!#...
#E ...
2 2
S.
! E
2 2
SE
!.Sample OutputYes
No
Yes
Topic Analysis: BFS1 pretreatment of each point magma arrived at the shortest time, BFS2 search whether to go out, to note that if the people and magma at the same time to E, then the person is successful escape
#include <cstdio> #include <cstring> #include <queue>using namespace std;int const MAX = 1005;int Const I NF = 0x7fffffff;char Map[max][max];int tim[max][max];bool vis[max][max];int N, m;int SX, Sy, EX, ey;int dx[4] = {1, 0,-1, 0};int Dy[4] = {0,-1, 0, 1};struct node{int x, Y;int step;}; bool OK (int i, int j) {if (i >= 0 && J >= 0 && i < n && J < m) return True;return false;} void BFS1 () {NODE yj;queue <NODE> q;for (int i = 0; i < n; i++) {for (int j = 0; J < m; J + +) {if (map[i][j] = = '! ') {yj.x = I;yj.y = J;yj.step = 0;tim[i][j] = 0;q.push (YJ);}}} while (!q.empty ()) {NODE now = Q.front (), T;q.pop ()//printf ("now.x =%d Now.y =%d Now.step =%d\n", now.x, Now.y, Now.st EP); for (int i = 0; i < 4; i + +) {t.x = now.x + dx[i];t.y = now.y + dy[i];t.step = now.step + 1;if (ok (t.x, T.Y) && ; T.step < Tim[t.x][t.y]) {Tim[t.x][t.y] = T.step;q.push (t);}} return;} BOOL BFS2 () {memset (Vis, false, sizeof (VIS)); NODE st;st.x = Sx;st.y = sy;vis[Sx][sy] = True;st.step = 0;queue <NODE> Qq;qq.push (ST), while (!qq.empty ()) {NODE now = Qq.front (), T;qq.pop (); . x = = Ex && now.y = = ey && t.step <= Tim[t.x][t.y]) return true;for (int i = 0; i < 4; i++) {t.x = now. x + dx[i];t.y = now.y + dy[i];t.step = now.step + 1;if (t.x = ex && t.y = ey && t.step <= Tim[t.x][t.y ] Return true;if (OK (t.x, T.Y) &&!vis[t.x][t.y] && t.step < Tim[t.x][t.y]) {Vis[t.x][t.y] = true; Qq.push (t);}}} return false;} int main () {int t;while (scanf ("%d", &t)! = EOF) {while (t--) {scanf ("%d%d", &n, &m), if (n = = 0 | | m = = 0) {printf (" No\n "); continue;} for (int i = 0; i < n; i++) {scanf ("%s", Map[i]), for (int j = 0; J < m; J + +) {Tim[i][j] = inf;if (map[i][j] = = ' s ') {SX = I;sy = j;} if (map[i][j] = = ' E ') {ex = I;ey = j;} if (map[i][j] = = ' # ') tim[i][j] = 0;}} BFS1 ();p rintf ("%s\n", BFS2 ()? "Yes": "No");}}}
problem 2197 minimum cost
Time limit:1000 mSec Memory limit:32768 KB problem Descriptionto a "01" string of length n (n <= 10^5), you can swap a bit for 0 and a bit for 1, if the two bits are adjacent, it costs X, otherwise it costs Y. The minimum cost of transforming the "1" in the string to the front of "0" after several exchanges. InputThe first line is an integer t (1 <= T <= 10), which represents the number of groups of test data. Next 3*t rows, three rows per set of data, first behavior integer X (1 <= X <= 10^3), second behavior integer Y (X <= Y <= 10^3), and the third row is the "01" string. Outputminimum cost. Sample Input2
1
2
1100
1
2
0011Sample Output0
3
Title Analysis: Two strategies, cross-change, adjacent, first the cost of the adjacent exchange is fixed, so a 1 and a 0, to exchange the cost of min (y, x * len)
First processing all 1 positions and the number of CNT, we want to let the former CNT is 1, then from 0 to Cnt-1 enumeration, encounter a 0 then take the last one 1 and it exchange
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;int const MAX = 1e5;char s[ Max];int Idx[max];int Main () {int t;scanf ("%d", &t), while (t--) {int x, y;scanf ("%d%d", &x, &y), scanf ("%s", s) ; int len = strlen (s), cnt = 0;for (int i = len-1; I >= 0; i--) if (s[i] = = ' 1 ') idx[cnt + +] = i;int ans = 0, now = 0;for ( int i = 0; I < CNT; i++) if (s[i] = = ' 0 ') ans + = min (y, x * (Idx[now + +]-i));p rintf ("%d\n", ans);}}
12th Session of Fuzhou University Program Design Competition (part of the puzzle)