2018第九届蓝桥省赛题目
標(biāo)題:第幾天
2000年的1月1日,是那一年的第1天。
那么,2000年的5月4日,是那一年的第幾天? ?
注意:需要提交的是一個(gè)整數(shù),不要填寫任何多余內(nèi)容。
該題很簡(jiǎn)單:125
?
標(biāo)題:明碼
漢字的字形存在于字庫中,即便在今天,16點(diǎn)陣的字庫也仍然使用廣泛。
16點(diǎn)陣的字庫把每個(gè)漢字看成是16x16個(gè)像素信息。并把這些信息記錄在字節(jié)中。
一個(gè)字節(jié)可以存儲(chǔ)8位信息,用32個(gè)字節(jié)就可以存一個(gè)漢字的字形了。
把每個(gè)字節(jié)轉(zhuǎn)為2進(jìn)制表示,1表示墨跡,0表示底色。每行2個(gè)字節(jié),
一共16行,布局是:
? ? 第1字節(jié),第2字節(jié)
? ? 第3字節(jié),第4字節(jié)
? ? ....
? ? 第31字節(jié), 第32字節(jié)
這道題目是給你一段多個(gè)漢字組成的信息,每個(gè)漢字用32個(gè)字節(jié)表示,這里給出了字節(jié)作為有符號(hào)整數(shù)的值。
題目的要求隱藏在這些信息中。你的任務(wù)是復(fù)原這些漢字的字形,從中看出題目的要求,并根據(jù)要求填寫答案。
這段信息是(一共10個(gè)漢字):
4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0?
16 64 16 64 34 68 127 126 66 -124 67 4 66 4 66 -124 126 100 66 36 66 4 66 4 66 4 126 4 66 40 0 16?
4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0?
0 -128 64 -128 48 -128 17 8 1 -4 2 8 8 80 16 64 32 64 -32 64 32 -96 32 -96 33 16 34 8 36 14 40 4?
4 0 3 0 1 0 0 4 -1 -2 4 0 4 16 7 -8 4 16 4 16 4 16 8 16 8 16 16 16 32 -96 64 64?
16 64 20 72 62 -4 73 32 5 16 1 0 63 -8 1 0 -1 -2 0 64 0 80 63 -8 8 64 4 64 1 64 0 -128?
0 16 63 -8 1 0 1 0 1 0 1 4 -1 -2 1 0 1 0 1 0 1 0 1 0 1 0 1 0 5 0 2 0?
2 0 2 0 7 -16 8 32 24 64 37 -128 2 -128 12 -128 113 -4 2 8 12 16 18 32 33 -64 1 0 14 0 112 0?
1 0 1 0 1 0 9 32 9 16 17 12 17 4 33 16 65 16 1 32 1 64 0 -128 1 0 2 0 12 0 112 0?
0 0 0 0 7 -16 24 24 48 12 56 12 0 56 0 -32 0 -64 0 -128 0 0 0 0 1 -128 3 -64 1 -128 0 0?
注意:需要提交的是一個(gè)整數(shù),不要填寫任何多余內(nèi)容。
?
題解:使用STL中的bitset()比較容易求解
得到一句話:九的九次方是多少?
答案:387420489
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<string> #include<bitset>using namespace std;int main() {int a, b;while(cin >> a >> b){bitset<8> bt(a);string s1 = bt.to_string();for(int i = 0; i < s1.length(); i++){if(s1[i] == '0') printf(" ");else printf("*");}bitset<8> bt2(b);string s2 = bt2.to_string();for(int i = 0; i < s2.length(); i++){if(s2[i] == '0') printf(" ");else printf("*");}printf("\n");}return 0; }?
標(biāo)題:乘積尾零
如下的10行數(shù)據(jù),每行有10個(gè)整數(shù),請(qǐng)你求出它們的乘積的末尾有多少個(gè)零?
5650 4542 3554 473 946 4114 3871 9073 90 4329?
2758 7949 6113 5659 5245 7432 3051 4434 6704 3594?
9937 1173 6866 3397 4759 7557 3070 2287 1453 9899?
1486 5722 3135 1170 4014 5510 5120 729 2880 9019?
2049 698 4582 4346 4427 646 9742 7340 1230 7683?
5693 7015 6887 7381 4172 4341 2909 2027 7355 5649?
6701 6645 1671 5978 2704 9926 295 3125 3878 6785?
2066 4247 4800 1578 6652 4616 1113 6205 3264 2915?
3966 5291 2904 1285 2193 1428 2265 8730 9436 7074?
689 5510 8243 6114 337 4096 8199 7313 3685 211?
注意:需要提交的是一個(gè)整數(shù),表示末尾零的個(gè)數(shù)。不要填寫任何多余內(nèi)容。
?
答案:31
JAVA大數(shù):
package text; import java.math.*; public class sum {public static void main(String[] args) {int num[] = {5650 ,4542 ,3554, 473 ,946, 4114 ,3871, 9073 ,90, 4329 ,2758 ,7949 ,6113, 5659 ,5245, 7432, 3051, 4434, 6704 ,3594, 9937 ,1173 ,6866 ,3397, 4759, 7557 ,3070 ,2287 ,1453, 9899 ,1486 ,5722 ,3135 ,1170, 4014 ,5510, 5120, 729,2880, 9019 ,2049 ,698, 4582, 4346, 4427, 646 ,9742 ,7340 ,1230, 7683 ,5693, 7015, 6887, 7381, 4172, 4341, 2909, 2027, 7355, 5649 ,6701, 6645, 1671, 5978 ,2704, 9926, 295, 3125, 3878, 6785 ,2066 ,4247, 4800 ,1578, 6652, 4616, 1113 ,6205, 3264, 2915 ,3966, 5291, 2904, 1285, 2193, 1428 ,2265 ,8730, 9436, 7074 ,689 ,5510 ,8243, 6114, 337, 4096, 8199, 7313 ,3685, 211};BigInteger sum, tmp;sum = BigInteger.valueOf(1);for(int i = 0;i < num.length;i ++){tmp = BigInteger.valueOf(num[i]);sum = sum.multiply(tmp);}System.out.println(sum);}}c++實(shí)現(xiàn):只需要找出2和5的最小組合
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<string> #include<map> #include<cmath>using namespace std;int a[] = {5650, 4542, 3554, 473, 946, 4114, 3871, 9073, 90, 4329, 2758, 7949, 6113, 5659, 5245, 7432, 3051, 4434, 6704, 3594, 9937, 1173, 6866, 3397, 4759, 7557, 3070, 2287, 1453, 9899, 1486, 5722, 3135, 1170, 4014, 5510, 5120, 729, 2880, 9019, 2049, 698, 4582, 4346, 4427, 646, 9742, 7340, 1230, 7683, 5693, 7015, 6887, 7381, 4172, 4341, 2909, 2027, 7355, 5649, 6701, 6645, 1671, 5978, 2704, 9926, 295, 3125, 3878, 6785, 2066, 4247, 4800, 1578, 6652, 4616, 1113, 6205, 3264, 2915, 3966, 5291, 2904, 1285, 2193, 1428, 2265, 8730, 9436, 7074, 689, 5510, 8243, 6114, 337, 4096, 8199, 7313, 3685 ,211};int main() {int ans1 = 0, ans2 = 0;int sum1 = 0, sum2 = 0;for(int i = 0; i < 100; i++){int t = a[i];for(int j = 2; j*j < t; j++){int cnt = 0;while(t % j == 0){t /= j;cnt++;}if(j == 2) ans1 = cnt;if(j == 5) ans2 = cnt;}if(t != 1){if(t == 2) ans1 = 1;if(t == 5) ans2 = 1;}sum1 += ans1; sum2 += ans2;}printf("%d %d\n", sum1, sum2);return 0; }?
標(biāo)題:測(cè)試次數(shù)
x星球的居民脾氣不太好,但好在他們生氣的時(shí)候唯一的異常舉動(dòng)是:摔手機(jī)。
各大廠商也就紛紛推出各種耐摔型手機(jī)。x星球的質(zhì)監(jiān)局規(guī)定了手機(jī)必須經(jīng)過耐摔測(cè)試,并且評(píng)定出一個(gè)耐摔指數(shù)來,之后才允許上市流通。
x星球有很多高聳入云的高塔,剛好可以用來做耐摔測(cè)試。塔的每一層高度都是一樣的,與地球上稍有不同的是,他們的第一層不是地面,而是相當(dāng)于我們的2樓。
如果手機(jī)從第7層扔下去沒摔壞,但第8層摔壞了,則手機(jī)耐摔指數(shù)=7。
特別地,如果手機(jī)從第1層扔下去就壞了,則耐摔指數(shù)=0。
如果到了塔的最高層第n層扔沒摔壞,則耐摔指數(shù)=n
為了減少測(cè)試次數(shù),從每個(gè)廠家抽樣3部手機(jī)參加測(cè)試。
某次測(cè)試的塔高為1000層,如果我們總是采用最佳策略,在最壞的運(yùn)氣下最多需要測(cè)試多少次才能確定手機(jī)的耐摔指數(shù)呢?
請(qǐng)?zhí)顚戇@個(gè)最多測(cè)試次數(shù)。
注意:需要填寫的是一個(gè)整數(shù),不要填寫任何多余內(nèi)容。
?
?
標(biāo)題:快速排序。?
以下代碼可以從數(shù)組a[]中找出第k小的元素。
它使用了類似快速排序中的分治算法,期望時(shí)間復(fù)雜度是O(N)的。
請(qǐng)仔細(xì)閱讀分析源碼,填寫劃線部分缺失的內(nèi)容。
#include <stdio.h>
int quick_select(int a[], int l, int r, int k) {
?? ?int p = rand() % (r - l + 1) + l;
?? ?int x = a[p];
?? ?{int t = a[p]; a[p] = a[r]; a[r] = t;}
?? ?int i = l, j = r;
?? ?while(i < j) {
?? ??? ?while(i < j && a[i] < x) i++;
?? ??? ?if(i < j) {
?? ??? ??? ?a[j] = a[i];
?? ??? ??? ?j--;
?? ??? ?}
?? ??? ?while(i < j && a[j] > x) j--;
?? ??? ?if(i < j) {
?? ??? ??? ?a[i] = a[j];
?? ??? ??? ?i++;
?? ??? ?}
?? ?}
?? ?a[i] = x;
?? ?p = i;
?? ?if(i - l + 1 == k) return a[i];
?? ?if(i - l + 1 < k) return quick_select( _____________________________ ); //填空
?? ?else return quick_select(a, l, i - 1, k);
}
?? ?
int main()
{
?? ?int a[] = {1, 4, 2, 8, 5, 7, 23, 58, 16, 27, 55, 13, 26, 24, 12};
?? ?printf("%d\n", quick_select(a, 0, 14, 5));
?? ?return 0;
}
注意:只填寫劃線部分缺少的代碼,不要抄寫已經(jīng)存在的代碼或符號(hào)。
快排填空,很容易:quick_select(a, i+1, r, k - (i-l+1));
?
標(biāo)題:遞增三元組
給定三個(gè)整數(shù)數(shù)組
A = [A1, A2, ... AN],?
B = [B1, B2, ... BN],?
C = [C1, C2, ... CN],
請(qǐng)你統(tǒng)計(jì)有多少個(gè)三元組(i, j, k) 滿足:
1. 1 <= i, j, k <= N ?
2. Ai < Bj < Ck ?
【輸入格式】?
第一行包含一個(gè)整數(shù)N。
第二行包含N個(gè)整數(shù)A1, A2, ... AN。
第三行包含N個(gè)整數(shù)B1, B2, ... BN。
第四行包含N個(gè)整數(shù)C1, C2, ... CN。
對(duì)于30%的數(shù)據(jù),1 <= N <= 100 ?
對(duì)于60%的數(shù)據(jù),1 <= N <= 1000?
對(duì)于100%的數(shù)據(jù),1 <= N <= 100000 0 <= Ai, Bi, Ci <= 100000?
【輸出格式】
一個(gè)整數(shù)表示答案
【樣例輸入】
3
1 1 1
2 2 2
3 3 3
【樣例輸出】
27?
資源約定:
峰值內(nèi)存消耗(含虛擬機(jī)) < 256M
CPU消耗 ?< 1000ms
請(qǐng)嚴(yán)格按要求輸出,不要畫蛇添足地打印類似:“請(qǐng)您輸入...” 的多余內(nèi)容。
注意:
main函數(shù)需要返回0;
只使用ANSI C/ANSI C++ 標(biāo)準(zhǔn);
不要調(diào)用依賴于編譯環(huán)境或操作系統(tǒng)的特殊函數(shù)。
所有依賴的函數(shù)必須明確地在源文件中 #include <xxx>
不能通過工程設(shè)置而省略常用頭文件。
提交程序時(shí),注意選擇所期望的語言類型和編譯器類型。
?
?
?
標(biāo)題:螺旋折線
?
如圖p1.png所示的螺旋折線經(jīng)過平面上所有整點(diǎn)恰好一次。 ?
對(duì)于整點(diǎn)(X, Y),我們定義它到原點(diǎn)的距離dis(X, Y)是從原點(diǎn)到(X, Y)的螺旋折線段的長度。 ?
?
例如dis(0, 1)=3, dis(-2, -1)=9 ?
?
給出整點(diǎn)坐標(biāo)(X, Y),你能計(jì)算出dis(X, Y)嗎?
?
【輸入格式】
X和Y ?
?
對(duì)于40%的數(shù)據(jù),-1000 <= X, Y <= 1000 ?
對(duì)于70%的數(shù)據(jù),-100000 <= X, Y <= 100000 ?
對(duì)于100%的數(shù)據(jù), -1000000000 <= X, Y <= 1000000000 ?
?
【輸出格式】
輸出dis(X, Y) ?
?
?
【樣例輸入】
0 1
?
【樣例輸出】
3
?
?
資源約定:
峰值內(nèi)存消耗(含虛擬機(jī)) < 256M
CPU消耗 ?< 1000ms
?
?
請(qǐng)嚴(yán)格按要求輸出,不要畫蛇添足地打印類似:“請(qǐng)您輸入...” 的多余內(nèi)容。
?
注意:
main函數(shù)需要返回0;
只使用ANSI C/ANSI C++ 標(biāo)準(zhǔn);
不要調(diào)用依賴于編譯環(huán)境或操作系統(tǒng)的特殊函數(shù)。
所有依賴的函數(shù)必須明確地在源文件中 #include <xxx>
不能通過工程設(shè)置而省略常用頭文件。
?
提交程序時(shí),注意選擇所期望的語言類型和編譯器類型。
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<string> #include<cmath>using namespace std;typedef long long LL; LL x, y;int main() {LL sum = 0;scanf("%lld%lld", &x, &y);if(x == 0 && y == 0) sum = 0;else if(x == -1 && y == 0) sum = 1;else if(x > 0 && y > 0){ //第一象限 LL col1, col2, row1, row2;if(x >= y){col1 = x;row1 = x;col2 = x;row2 = x-1;sum += col1 + col1*(col1-1) * 2 / 2;sum += row1 + row1*(row1-1) * 2 / 2;sum += 2*col2 + col2*(col2-1) * 2 / 2;sum += 2*row2 + row2*(row2-1) * 2 / 2;sum += x-y;}else{col1 = y;row1 = y;col2 = y-1;row2 = y-1;sum += col1 + col1*(col1-1) * 2 / 2;sum += row1 + row1*(row1-1) * 2 / 2;sum += 2*col2 + col2*(col2-1) * 2 / 2;sum += 2*row2 + row2*(row2-1) * 2 / 2;sum += y;sum += x;}}else if(x > 0 && y < 0){ //第二象限 LL col1, col2, row1, row2; if(x >= abs(y)){col1 = x;row1 = x;row2 = x;col2 = x-1;sum += col1 + col1*(col1-1) * 2 / 2;sum += row1 + row1*(row1-1) * 2 / 2;sum += 2*col2 + col2*(col2-1) * 2 / 2;sum += 2*row2 + row2*(row2-1) * 2 / 2;sum += x;sum += abs(y); }else{col1 = abs(y);row1 = abs(y);col2 = abs(y);row2 = abs(y);sum += col1 + col1*(col1-1) * 2 / 2;sum += row1 + row1*(row1-1) * 2 / 2;sum += 2*col2 + col2*(col2-1) * 2 / 2;sum += 2*row2 + row2*(row2-1) * 2 / 2;sum += abs(y)-x;}}else if(x < 0 && y < 0){ //第三象限 LL col1, col2, row1, row2;if(abs(x) <= abs(y)+1){col1 = abs(y);row1 = abs(y);col2 = abs(y);row2 = abs(y);sum += col1 + col1*(col1-1) * 2 / 2;sum += row1 + row1*(row1-1) * 2 / 2;sum += 2*col2 + col2*(col2-1) * 2 / 2;sum += 2*row2 + row2*(row2-1) * 2 / 2;sum += abs(y);sum += abs(x); }else{col1 = abs(x);row1 = abs(x)-1;col2 = abs(x)-1;row2 = abs(x)-1;sum += col1 + col1*(col1-1) * 2 / 2;sum += row1 + row1*(row1-1) * 2 / 2;sum += 2*col2 + col2*(col2-1) * 2 / 2;sum += 2*row2 + row2*(row2-1) * 2 / 2;sum += abs(x) - abs(y);}}else if(x < 0 && y > 0){ //第四象限 LL col1, col2, row1, row2;if(abs(x) >= y){col1 = abs(x);row1 = abs(x)-1;col2 = abs(x)-1;row2 = abs(x)-1;sum += col1 + col1*(col1-1) * 2 / 2;sum += row1 + row1*(row1-1) * 2 / 2;sum += 2*col2 + col2*(col2-1) * 2 / 2;sum += 2*row2 + row2*(row2-1) * 2 / 2;sum += abs(x)-1;sum += y;}else{col1 = y;row1 = y;col2 = y-1;row2 = y-1;sum += col1 + col1*(col1-1) * 2 / 2;sum += row1 + row1*(row1-1) * 2 / 2;sum += 2*col2 + col2*(col2-1) * 2 / 2;sum += 2*row2 + row2*(row2-1) * 2 / 2;sum += y-abs(x);}}//坐標(biāo)軸 else if(y == 0 && x > 0){LL col1, col2, row1, row2;col1 = x;row1 = x;row2 = x;col2 = x-1;sum += col1 + col1*(col1-1) * 2 / 2;sum += row1 + row1*(row1-1) * 2 / 2;sum += 2*col2 + col2*(col2-1) * 2 / 2;sum += 2*row2 + row2*(row2-1) * 2 / 2;sum += y;}else if(x == 0 && y < 0){LL col1, col2, row1, row2;col1 = abs(y);row1 = abs(y);col2 = abs(y);row2 = abs(y);sum += col1 + col1*(col1-1) * 2 / 2;sum += row1 + row1*(row1-1) * 2 / 2;sum += 2*col2 + col2*(col2-1) * 2 / 2;sum += 2*row2 + row2*(row2-1) * 2 / 2;sum += abs(y);}else if(y == 0 && x < 0){LL col1, row1, col2, row2;col1 = abs(x);row1 = abs(x)-1;col2 = abs(x)-1;row2 = abs(x)-1;sum += col1 + col1*(col1-1) * 2 / 2;sum += row1 + row1*(row1-1) * 2 / 2;sum += 2*col2 + col2*(col2-1) * 2 / 2;sum += 2*row2 + row2*(row2-1) * 2 / 2;sum += abs(x)-1;}else if(x == 0 && y > 0){LL col1, col2, row1, row2;col1 = y;row1 = y;col2 = y-1;row2 = y-1;sum += col1 + col1*(col1-1) * 2 / 2;sum += row1 + row1*(row1-1) * 2 / 2;sum += 2*col2 + col2*(col2-1) * 2 / 2;sum += 2*row2 + row2*(row2-1) * 2 / 2;sum += y;}printf("%lld\n", sum);return 0; }?
?
?
?
?
總結(jié)
以上是生活随笔為你收集整理的2018第九届蓝桥省赛题目的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。