"高教社杯"第三屆福建省大學生程式設計競賽

來源:互聯網
上載者:User
 A.Problem 2102 Solve equation Accept: 1032    Submit: 2471
Time Limit: 1000 mSec    Memory Limit : 32768 KB
 Problem Description

You are given two positive integers A and B in Base C. For the equation:

A=k*B+d

We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.

For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:

(1) A=0*B+123

(2) A=1*B+23

As we want to maximize k, we finally get one solution: (1, 23)

The range of C is between 2 and 16, and we use 'a', 'b', 'c', 'd', 'e', 'f' to represent 10, 11, 12, 13, 14, 15, respectively.  Input

The first line of the input contains an integer T (T≤10), indicating the number of test cases.

Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.  Output For each test case, output the solution “(k,d)” to the equation in Base 10.  Sample Input 32bc 33f 16123 100 101 1 2  Sample Output (0,700)(1,23)(1,0)  Source “高教社杯”第三屆福建省大學生程式設計競賽
題意:給你兩個數,他們是任意進位的,進位要求已經限制在2進位和16進位之間,然後求解讓A = k* B + d這個等式成立的最大的k值。 解題思路:將A, B兩個數先轉換為十進位(因為題目要求最終輸出的k和d的值必須是十進位的),然後對A % B = d,求解出d的值,然後k = (A - d) / B,即可。

#include <queue>#include <cmath>#include <cstdio>#include <string>#include <cstring>#include <iostream>#include <algorithm>using namespace std;//#pragma comment(linker, "/STACK:1024000000,1024000000")#define FIN             freopen("input.txt","r",stdin)#define FOUT            freopen("output.txt","w",stdout)#define fst             first#define snd             secondtypedef __int64  LL;typedef pair<int, int> PII;const double eps = 1e-10;const int MAXN = 1e2 + 5;const int INF  = 0x3f3f3f3f;int T, N, M;int c;char a[MAXN], b[MAXN];int get(char* s){    int t = 1, res = 0, len = strlen(s);;    for (int i = len - 1; i >= 0; i--, t *= c) {        if (s[i] >= 'a' && s[i] <= 'z')            res += (s[i] - 'a' + 10) * t;        else            res += (s[i] - '0') * t;    }    return res;}int main() {#ifndef ONLINE_JUDGE     FIN;    // FOUT;#endif // ONLINE_JUDGE    int cas = 0, res;    scanf("%d", &T);    while (T--) {        scanf("%s%s%d", a, b, &c);        int aa = get(a);        int bb = get(b);        printf("(%d,%d)\n", aa / bb, aa % bb);    }    return 0;}

 C.Problem 2104 Floor problem Accept: 1076    Submit: 1257
Time Limit: 1000 mSec    Memory Limit : 32768 KB
 Problem Description

In this problem, we have f(n,x)=Floor[n/x]. Here Floor[x] is the biggest integer such that no larger than x. For example, Floor[1.1]=Floor[1.9]=1, Floor[2.0]=2.

You are given 3 positive integers n, L and R. Print the result of f(n,L)+f(n,L+1)+...+f(n,R), please.  Input

The first line of the input contains an integer T (T≤100), indicating the number of test cases.

Then T cases, for any case, only 3 integers n, L and R (1≤n, L, R≤10,000, L≤R).  Output For each test case, print the result of f(n,L)+f(n,L+1)+...+f(n,R) in a single line.  Sample Input 31 2 3100 2 100100 3 100  Sample Output 0382332  Source “高教社杯”第三屆福建省大學生程式設計競賽
題意:求解給定數N,在[L,R]區間中的floor(N / i)的和 解題思路:直接暴力迴圈求和即可

#include <queue>#include <cmath>#include <cstdio>#include <string>#include <cstring>#include <iostream>#include <algorithm>using namespace std;//#pragma comment(linker, "/STACK:1024000000,1024000000")#define FIN             freopen("input.txt","r",stdin)#define FOUT            freopen("output.txt","w",stdout)#define fst             first#define snd             secondtypedef __int64  LL;typedef pair<int, int> PII;const double eps = 1e-10;const int MAXN = 1e7 + 5;const int INF  = 0x3f3f3f3f;int T, N, M;int main() {#ifndef ONLINE_JUDGE    FIN;    // FOUT;#endif // ONLINE_JUDGE    int cas = 0, res;    int L, R;    scanf ("%d", &T);    while (T --) {        res = 0;        scanf ("%d %d %d", &N, &L, &R);        for (int i = L; i <= R; i++) {            res += N / i;        }        printf ("%d\n", res);    }    return 0;}
 F.Problem 2107 Hua Rong Dao Accept: 372    Submit: 806
Time Limit: 1000 mSec    Memory Limit : 32768 KB
 Problem Description

Cao Cao was hunted down by thousands of enemy soldiers when he escaped from Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisle (one N*4 rectangle), while Cao Cao can be regarded as one 2*2 grid. Cross general can be regarded as one 1*2 grid.Vertical general can be regarded as one 2*1 grid. Soldiers can be regarded as one 1*1 grid. Now Hua Rong Dao is full of people, no grid is empty.

There is only one Cao Cao. The number of Cross general, vertical general, and soldier is not fixed. How many ways can all the people stand?  Input

There is a single integer T (T≤4) in the first line of the test data indicating that there are T test cases.

Then for each case, only one integer N (1≤N≤4) in a single line indicates the length of Hua Rong Dao.  Output For each test case, print the number of ways all the people can stand in a single line.  Sample Input 212  Sample Output 018  Hint

Here are 2 possible ways for the Hua Rong Dao 2*4.  Source “高教社杯”第三屆福建省大學生程式設計競賽
題意:給你一個N * 4(1 <= N <= 4)的矩形,讓你用四種不同的矩形覆蓋,這些矩形分別為1*1,2*1,2*1,2*2,其中2*2的矩形有且只有一塊,而其它三種矩形的個數沒有限制,最終必須覆蓋N*4的所有地方,然後求解有多少種覆蓋方法
解題思路:直接DFS不斷用著四種方法進行覆蓋求解就可以了

#include <queue>#include <cmath>#include <cstdio>#include <string>#include <cstring>#include <iostream>#include <algorithm>using namespace std;//#pragma comment(linker, "/STACK:1024000000,1024000000")#define FIN             freopen("input.txt","r",stdin)#define FOUT            freopen("output.txt","w",stdout)#define fst             first#define snd             secondtypedef __int64  LL;typedef pair<int, int> PII;const double eps = 1e-10;const int MAXN = 1e7 + 5;const int INF  = 0x3f3f3f3f;int T, N, M;LL ans = 0;bool cc, vis[5][5];void dfs (int x, int y) {if (x == N) {if (!cc)ans++;return;}int xx = x, yy = y + 1;if (yy > 3) {xx++;yy = 0;}if (vis[x][y]) {dfs (xx, yy);} else {for (int i = 0; i < 4; i++) {if (i == 0) { // 2 * 2if (!cc)continue;else {if (x + 1 < N && y + 1 < 4 && !vis[x + 1][y] && !vis[x][y + 1] && !vis[x + 1][y + 1]) {cc = false;vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x + 1][y + 1] = true;dfs (xx, yy);cc = true;vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x + 1][y + 1] = false;}}} else if (i == 1) { // 2 * 1if (x + 1 < N && !vis[x + 1][y]) {vis[x][y] = vis[x + 1][y] = true;dfs (xx, yy);vis[x][y] = vis[x + 1][y] = false;}} else if (i == 2) { // 1 * 2if (y + 1 < 4 && !vis[x][y + 1]) {vis[x][y] = vis[x][y + 1] = true;dfs (xx, yy);vis[x][y] = vis[x][y + 1] = false;}} else if (i == 3) { // 1 * 1vis[x][y] = true;dfs (xx, yy);vis[x][y] = false;}}}}int main() {#ifndef ONLINE_JUDGEFIN;// FOUT;#endif // ONLINE_JUDGEint cas = 0, res, ans[5] = {0, 0, 18, 284, 4862};scanf("%d", &T);while (T--) {scanf("%d", &N);printf("%d\n", ans[N]);}return 0;}<span style="font-size:12px;"></span>
G.Problem 2108 Mod problem Accept: 104    Submit: 432
Time Limit: 1000 mSec    Memory Limit : 32768 KB
 Problem Description

Given one non-negative integer A and one positive integer B, it’s very easy for us to calculate A Mod B. Here A Mod B means the remainder of the answer after A is divided by B. For example, 7 Mod 5 = 2, 12 Mod 3 = 0, 0 Mod 3 = 0.

In this problem, we use the following rules to express A.

(1) One non-empty string that only contains {0,1,2,3,4,5,6,7,8,9} is valid.

For example, 123, 000213, 99213. (Leading zeros is OK in this problem)

(2) If w is valid, then [w]x if valid. Here x is one integer that 0<x<10.

For example, [012]2=012012, [35]3[7]1=3535357.

(3) If w and v are valid, then wv is valid.

For example, w=[231]2 and v=1, then wv=[231]21 is valid (which is 2312311).

Now you are given A and B. Here A is express as the rules above and B is simply one integer, you are expected to output the A Mod B.  Input

The first line of the input contains an integer T(T≤10), indicating the number of test cases.

Then T cases, for any case, only two lines.

The first line is one non-empty and valid string that expresses A, the length of the string is no more than 1,000.

The second line is one integer B(0<B<2,000,000,000).

You may assume that the length of number A in decimal notation will less than 2^63.  Output For each test case, output A Mod B in a single line.  Sample Input 3
[0]9[[1]2]3
10007
[[213231414343214231]5]1
10007
[0012]1
1
 Sample Output 1034
3943
0
 Source “高教社杯”第三屆福建省大學生程式設計競賽
題意:給你一個字串A和一個數字B,其中這個字串中存在數字0-9以及'['和']',字串處理如下: [123]2=123123 [123]21=1231231 最終讓你求解這個字串最後形成的數字對B的模數 解題思路:可以通過ret = (ret * 10 % B + A[i] - '0') % B的思路來求解,然後通過遞迴思想,將[]中的數字一一求出即可

/*標頭檔模板*/#include <map>#include <set>#include <cmath>#include <ctime>#include <queue>#include <stack>#include <vector>#include <cctype>#include <cstdio>#include <string>#include <cstring>#include <sstream>#include <cstdlib>#include <iomanip>#include <typeinfo>#include <iostream>#include <algorithm>#include <functional>using namespace std;#define pb push_back#define mp make_pair#define mem(a, x) memset(a, x, sizeof(a))#define copy(a, b) memcpy(a, b, sizeof(a))#define lson rt << 1, l, mid#define rson rt << 1|1, mid + 1, r#define FIN freopen("input.txt", "r", stdin)#define FOUT freopen("output.txt", "w", stdout)typedef long long LL;typedef pair<int, int > PII;typedef pair<int, string> PIS;typedef pair<LL, int>PLI;typedef pair<LL, LL>PLL;typedef unsigned long long uLL;template<typename T>void print (T* p, T* q, string Gap = " ", bool flag = false) {int d = p < q ? 1 : -1;while (p != q) {if (flag) cout << Gap[0] << *p << Gap[1];else cout << *p;p += d;if (p != q && !flag) cout << Gap;}cout << endl;}template<typename T>void print (const T &a, string bes = "") {int len = bes.length();if (len >= 2) cout << bes[0] << a << bes[1] << endl;else cout << a << endl;}template<typename T>void debug (T* p, T* q, string Gap = " ", bool flag = false) {#ifndef ONLINE_JUDGEint d = p < q ? 1 : -1;cout << "Debug out : ";while (p != q) {if (flag) cout << Gap[0] << *p << Gap[1];else cout << *p;p += d;if (p != q && !flag) cout << Gap;}cout << endl;#endif}template<typename T>void debug (const T &a, string bes = "") {#ifndef ONLINE_JUDGEint len = bes.length();cout << "Debug out : ";if (len >= 2) cout << bes[0] << a << bes[1] << endl;else cout << a << endl;#endif}void IO_Init() {ios::sync_with_stdio (false);}LL LLabs (const LL a) {return a >= 0 ? a : -a;}const double PI = 3.1415926535898;const double eps = 1e-10;const int MAXM = 1e5 + 5;const int MAXN = 1e3 + 5;const int INF = 0x3f3f3f3f;/*標頭檔模板*/int T, slen;char A[MAXN];LL b;stack<char>C;LL mod_pow(LL x, int p, LL mod) {LL ret = 1;while(p > 0) {if(p & 1) ret = ret * x % mod;x = x * x % mod;p >>= 1;}return ret;}PLI solve(int &l) {int cnt = 0,len = 0;LL ans = 0;while(l < slen) {if(A[l] == '[') {int r = ++ l;PLI a = solve(r);int k = A[r + 1] - '0';for(int i = 0; i < k; i ++) {ans = (ans * mod_pow(10, a.second, b) % b + a.first) % b;}len += k * a.second;l = r + 2;} else if(A[l] == ']') {break;} else {ans = (ans * 10 % b + A[l ++] - '0') % b;len ++;}}return PLI(ans, len);}int main() {#ifndef ONLINE_JUDGE//FIN;//FOUT;#endifIO_Init();scanf("%d", &T);while(T --) {scanf("%s%I64d", A, &b);slen = strlen(A);int k = 0;printf("%I64d\n", solve(k).first);}return 0;}
 H.Problem 2109 Mountain Number Accept: 228    Submit: 571
Time Limit: 1000 mSec    Memory Limit : 32768 KB
 Problem Description

One integer number x is called "Mountain Number" if:

(1) x>0 and x is an integer;

(2) Assume x=a[0]a[1]...a[len-2]a[len-1](0≤a[i]≤9, a[0] is positive). Any a[2i+1] is larger or equal to a[2i] and a[2i+2](if exists).

For example, 111, 132, 893, 7 are "Mountain Number" while 123, 10, 76889 are not "Mountain Number".

Now you are given L and R, how many "Mountain Number" can be found between L and R (inclusive) ?  Input

The first line of the input contains an integer T (T≤100), indicating the number of test cases.

Then T cases, for any case, only two integers L and R (1≤L≤R≤1,000,000,000).  Output For each test case, output the number of "Mountain Number" between L and R in a single line.  Sample Input 31 101 1001 1000  Sample Output 954384  Source “高教社杯”第三屆福建省大學生程式設計競賽
題意:給你一個區間[L,R]求解這個區間中滿足奇數位大於相鄰偶數位的數位個數。 解題思路:典型的數位DP,基本是道裸題,直接從高位處理,然後用在找尋下一位的時候,用一個變數標記當

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.