日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

## 弱鸡的第二次线上赛总结(TKK18no.4)

發(fā)布時(shí)間:2023/12/20 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ## 弱鸡的第二次线上赛总结(TKK18no.4) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

第一題:十六進(jìn)制

輸入一個(gè)十進(jìn)制正整數(shù),輸出這個(gè)數(shù)的十六進(jìn)制表示,其中十六進(jìn)制的10-15用大寫字母A-F表示。

不斷取余,將10-15的數(shù)替換成相應(yīng)大寫字母即可。

#include<iostream> #include<string> #include<cmath> #include<bitset> #include<algorithm> using namespace std; void D_TO_X(int x) {int i, j, arr[16];for (i = 0; x != 0; i++){arr[i] = x % 16;if (arr[i] <= 9){arr[i] += '0'; }else{switch (arr[i]){case 10:arr[i] = 'A'; break;case 11:arr[i] = 'B'; break;case 12:arr[i] = 'C'; break;case 13:arr[i] = 'D'; break;case 14:arr[i] = 'E'; break;case 15:arr[i] = 'F'; break;}}x /= 16;}for (j = i - 1; j >= 0; j--){cout.put(arr[j]);}cout << endl; }int main() {int n;cin >> n;while (n--){int k;cin >> k;D_TO_X(k);}return 0; }

第二題:畫矩形

只有一組案例。先是兩個(gè)正整數(shù)m和n(3<=m,n<=10),然后是一個(gè)字符c,最后是一個(gè)0或者1的整數(shù)d。m代表矩形圖案的高,n代表矩形圖案的寬,c是用來(lái)畫矩形的符號(hào),如果d是0則畫空心的矩形,如果d是1則畫實(shí)心的矩形。

比較基礎(chǔ),換成1與0兩種情況,逐行判斷輸出即可。

#include<iostream> #include<string> #include<cmath> #include<bitset> #include<algorithm> using namespace std;int main() {int m, n;char k;bool x;cin >> m >> n >> k >> x;if (x){for (int i = 0; i < m; i++){for (int i = 0; i < n; i++){cout << k;}cout << endl;}}else{for (int i = 0; i < m; i++){if (i == 0 || i == m - 1){for (int i = 0; i < n; i++){cout << k;}cout << endl;}else{cout << k;for (int i = 0; i < n-2; i++){cout << " ";}cout << k << endl;}}}return 0; }

第三題:從前有個(gè)函數(shù)

從前有個(gè)數(shù)學(xué)函數(shù)f(x),功能是計(jì)算x的因數(shù)的個(gè)數(shù),例如f(8)=4。(因?yàn)?的因數(shù)有1、2、4、8)后來(lái)有人覺(jué)得算一次f函數(shù)不過(guò)癮,又嵌套了一層,于是變成了f(f(x)),那么f(f(8))=f(4)=3。隨后,就有了更多層的嵌套函數(shù)f。人們發(fā)現(xiàn)這樣寫太費(fèi)事了,于是把嵌套層數(shù)當(dāng)成了f函數(shù)的第二個(gè)參數(shù),例如f(f(8))寫成了f(8,2),f(9)寫成了f(9,1)?,F(xiàn)在,需要計(jì)算f(a,b)=?

這里題目輸入的是十億以內(nèi)的數(shù),可見(jiàn)要節(jié)約時(shí)間。于是判素后直接取2,在sqrt下*2,完全平方數(shù)再加一。

#include<iostream> #include<algorithm> #include<cmath> #include<bitset> #include<string> using namespace std; bool f(int m) {for (int i = 2; i <= sqrt(m); i++){if (m%i == 0)return 0;}if (m>1)return 1;else return 0; }int main() {int n, m, p;cin >> n;while (n--){cin >> m >> p;while (p--){if (f(m)){m = 2; break;}if (m == 1)break;int sum = 0;for (int i = 1; i <= sqrt(m); i++){if (i*i == m)sum++;else if (m%i == 0)sum += 2;}m = sum;}cout << m << endl;} }

第四題:五毒教主吃蘋果

有一天,邪惡的巫師送給了五毒教主一筐蘋果,里面有一些正常的蘋果和一些有毒的蘋果。凡人吃毒蘋果輕則吐血,重則暴斃,然而五毒教主吃一個(gè)毒蘋果后只會(huì)昏睡一天,并無(wú)大礙?;杷哪翘煳?#xff0c;毒教主不吃蘋果。例如,第1天吃了一個(gè)毒蘋果,則第2天昏睡不吃,第3天繼續(xù)吃。
恰逢五毒教主最近減肥,每天最多只吃1個(gè)蘋果,直到吃完這一筐蘋果為止。
問(wèn):有多少種不同的吃法?(如果有一個(gè)正常的蘋果和一個(gè)毒蘋果,那么先吃正常蘋果再吃毒蘋果,和先吃毒蘋果再吃正常蘋果,屬于2種不同的吃法。)

看起來(lái)很嚇人,實(shí)際上就是遞歸。普通的蘋果和毒蘋果就是兩種東西,日期無(wú)所謂。

#include<iostream> #include<string> #include<cmath> #include<bitset> #include<algorithm> using namespace std; int t(int a, int b) {if (a == 0 && b == 0)return 1;else if (b == 0)return 1;else if (a == 0)return 1;else return t(a - 1, b) + t(a, b - 1); } int main() {int f;cin >> f;while (f--){int m, n;cin >> m >> n;cout << t(m, n) << endl;}return 0; }

第五題:算出18

有3個(gè)非負(fù)的整數(shù),想看看是否能夠通過(guò)加減乘除運(yùn)算,使得答案為18。
每個(gè)數(shù)字必須都用上,且僅能各使用一次。不要求按照順序使用,可以添加上適當(dāng)?shù)睦ㄌ?hào)以改變計(jì)算順序。
注意:除法是按照數(shù)學(xué)上的運(yùn)算結(jié)果。

這道題有兩種做法,一種是暴力,一種還是遞歸。要考慮到0的情況和是否用到所有數(shù),是否有浮點(diǎn)數(shù)誤差,還有數(shù)的順序可以替換問(wèn)題。

#include<iostream> #include<string> #include<cmath> #include<bitset> #include<algorithm> using namespace std;int main() {int f;cin >> f;while (f--){double x1, x2, x3;cin >> x1 >> x2 >> x3;double a = x1; double b = x2; double c = x3;int d = 0;if (a + b + c == 18)d = 1;else if (a + b - c == 18)d = 1;else if (a + b * c == 18)d = 1;else if (c!=0&&a + b / c == 18)d = 1;else if ((a + b) * c == 18)d = 1;else if (c != 0 && (a + b) / c == 18)d = 1;else if (a - b + c == 18)d = 1;else if (a - b - c == 18)d = 1;else if (a - b * c == 18)d = 1;else if (c != 0 && a - b / c == 18)d = 1;else if ((a - b) * c == 18)d = 1;else if (c != 0 && (a - b) / c == 18)d = 1;else if (a * b + c == 18)d = 1;else if (a * b - c == 18)d = 1;else if (a * b * c == 18)d = 1;else if (c != 0 && a * b / c == 18)d = 1;else if (a * (b + c) == 18)d = 1;else if (a * (b - c) == 18)d = 1;else if (a / b + c == 18)d = 1;else if (a / b - c == 18)d = 1;else if (a / b * c == 18)d = 1;else if (c != 0 &&b!=0&& a / b / c == 18)d = 1;else if (b+c!=0&&a / (b + c) == 18)d = 1;else if (b-c!=0&&a / (b - c) == 18)d = 1;a = x2; b = x1; c = x3;if (a + b + c == 18)d = 1;else if (a + b - c == 18)d = 1;else if (a + b * c == 18)d = 1;else if (c != 0 && a + b / c == 18)d = 1;else if ((a + b) * c == 18)d = 1;else if (c != 0 && (a + b) / c == 18)d = 1;else if (a - b + c == 18)d = 1;else if (a - b - c == 18)d = 1;else if (a - b * c == 18)d = 1;else if (c != 0 && a - b / c == 18)d = 1;else if ((a - b) * c == 18)d = 1;else if (c != 0 && (a - b) / c == 18)d = 1;else if (a * b + c == 18)d = 1;else if (a * b - c == 18)d = 1;else if (a * b * c == 18)d = 1;else if (c != 0 && a * b / c == 18)d = 1;else if (a * (b + c) == 18)d = 1;else if (a * (b - c) == 18)d = 1;else if (a / b + c == 18)d = 1;else if (a / b - c == 18)d = 1;else if (a / b * c == 18)d = 1;else if (c != 0 && b != 0 && a / b / c == 18)d = 1;else if (b + c != 0 && a / (b + c) == 18)d = 1;else if (b - c != 0 && a / (b - c) == 18)d = 1;a = x1; b = x3; c = x2;if (a + b + c == 18)d = 1;else if (a + b - c == 18)d = 1;else if (a + b * c == 18)d = 1;else if (c != 0 && a + b / c == 18)d = 1;else if ((a + b) * c == 18)d = 1;else if (c != 0 && (a + b) / c == 18)d = 1;else if (a - b + c == 18)d = 1;else if (a - b - c == 18)d = 1;else if (a - b * c == 18)d = 1;else if (c != 0 && a - b / c == 18)d = 1;else if ((a - b) * c == 18)d = 1;else if (c != 0 && (a - b) / c == 18)d = 1;else if (a * b + c == 18)d = 1;else if (a * b - c == 18)d = 1;else if (a * b * c == 18)d = 1;else if (c != 0 && a * b / c == 18)d = 1;else if (a * (b + c) == 18)d = 1;else if (a * (b - c) == 18)d = 1;else if (a / b + c == 18)d = 1;else if (a / b - c == 18)d = 1;else if (a / b * c == 18)d = 1;else if (c != 0 && b != 0 && a / b / c == 18)d = 1;else if (b + c != 0 && a / (b + c) == 18)d = 1;else if (b - c != 0 && a / (b - c) == 18)d = 1;a = x2; b = x3; c = x1;if (a + b + c == 18)d = 1;else if (a + b - c == 18)d = 1;else if (a + b * c == 18)d = 1;else if (c != 0 && a + b / c == 18)d = 1;else if ((a + b) * c == 18)d = 1;else if (c != 0 && (a + b) / c == 18)d = 1;else if (a - b + c == 18)d = 1;else if (a - b - c == 18)d = 1;else if (a - b * c == 18)d = 1;else if (c != 0 && a - b / c == 18)d = 1;else if ((a - b) * c == 18)d = 1;else if (c != 0 && (a - b) / c == 18)d = 1;else if (a * b + c == 18)d = 1;else if (a * b - c == 18)d = 1;else if (a * b * c == 18)d = 1;else if (c != 0 && a * b / c == 18)d = 1;else if (a * (b + c) == 18)d = 1;else if (a * (b - c) == 18)d = 1;else if (a / b + c == 18)d = 1;else if (a / b - c == 18)d = 1;else if (a / b * c == 18)d = 1;else if (c != 0 && b != 0 && a / b / c == 18)d = 1;else if (b + c != 0 && a / (b + c) == 18)d = 1;else if (b - c != 0 && a / (b - c) == 18)d = 1;a = x3; b = x1; c = x2;if (a + b + c == 18)d = 1;else if (a + b - c == 18)d = 1;else if (a + b * c == 18)d = 1;else if (c != 0 && a + b / c == 18)d = 1;else if ((a + b) * c == 18)d = 1;else if (c != 0 && (a + b) / c == 18)d = 1;else if (a - b + c == 18)d = 1;else if (a - b - c == 18)d = 1;else if (a - b * c == 18)d = 1;else if (c != 0 && a - b / c == 18)d = 1;else if ((a - b) * c == 18)d = 1;else if (c != 0 && (a - b) / c == 18)d = 1;else if (a * b + c == 18)d = 1;else if (a * b - c == 18)d = 1;else if (a * b * c == 18)d = 1;else if (c != 0 && a * b / c == 18)d = 1;else if (a * (b + c) == 18)d = 1;else if (a * (b - c) == 18)d = 1;else if (a / b + c == 18)d = 1;else if (a / b - c == 18)d = 1;else if (a / b * c == 18)d = 1;else if (c != 0 && b != 0 && a / b / c == 18)d = 1;else if (b + c != 0 && a / (b + c) == 18)d = 1;else if (b - c != 0 && a / (b - c) == 18)d = 1;a = x3; b = x2; c = x1;if (a + b + c == 18)d = 1;else if (a + b - c == 18)d = 1;else if (a + b * c == 18)d = 1;else if (c != 0 && a + b / c == 18)d = 1;else if ((a + b) * c == 18)d = 1;else if (c != 0 && (a + b) / c == 18)d = 1;else if (a - b + c == 18)d = 1;else if (a - b - c == 18)d = 1;else if (a - b * c == 18)d = 1;else if (c != 0 && a - b / c == 18)d = 1;else if ((a - b) * c == 18)d = 1;else if (c != 0 && (a - b) / c == 18)d = 1;else if (a * b + c == 18)d = 1;else if (a * b - c == 18)d = 1;else if (a * b * c == 18)d = 1;else if (c != 0 && a * b / c == 18)d = 1;else if (a * (b + c) == 18)d = 1;else if (a * (b - c) == 18)d = 1;else if (a / b + c == 18)d = 1;else if (a / b - c == 18)d = 1;else if (a / b * c == 18)d = 1;else if (c != 0 && b != 0 && a / b / c == 18)d = 1;else if (b + c != 0 && a / (b + c) == 18)d = 1;else if (b - c != 0 && a / (b - c) == 18)d = 1;if (d == 1)cout << "Yes";else cout << "No";cout << endl;}return 0; }

這是我的第一種做法,很蠢但至少過(guò)了。

#include<iostream> #include<cmath> using namespace std; bool isSame(double a, double b) {if (abs(a - b) <= 1e-7){return true;}else{return false;} } bool can2(double result, int first, int second) {if (first + second == result|| first - second == result|| second - first == result|| first * second == result|| second != 0 && isSame(1.0 * first / second, result)|| first != 0 && isSame(1.0 * second / first, result)){return true;}else{return false;} } bool can31(double result, int first, int second, int third) {if (can2(result - first, second, third)|| can2(first - result, second, third)|| can2(result + first, second, third)|| (result == 0 && first == 0 || first != 0) && can2(result*first, second, third)|| first != 0 && can2(result / first, second, third)|| result != 0 && first != 0 && can2(first / result, second, third)){return true;}else{return false;} } bool can3(double result, int first, int second, int third) {if (can31(result, first, second, third)|| can31(result, second, first, third)|| can31(result, third, first, second)){return true;}else{return false;} } int main() {const double result = 18;int n;cin >> n;while (n--){int a, b, c;cin >> a >> b >> c;if (can3(result, a, b, c)){cout << "Yes" << endl;}else{cout << "No" << endl;}}return 0; }

這是遞歸的做法,比較高難。

第六題:字符陣列

輸出m行m列由字符組成的陣列。其特點(diǎn)是按照字母表順序蛇形走位,第一行是順序,第二行是倒序,…。另外,當(dāng)用到字符Z后,下一個(gè)字符是A。

舉個(gè)栗子,就是3的話,會(huì)變成
ABC
FED
GHI
這個(gè)按坐標(biāo)算出來(lái)在自己所在的字符串第幾個(gè),再輸出ascii對(duì)應(yīng)的字母就行。

#include<iostream> #include<string> #include<cmath> #include<bitset> #include<algorithm> using namespace std;int main() {int f;cin >> f;while (f--){int m;cin >> m;for (int i = 1; i <= m; i++){for (int p = 1; p <= m; p++){if (i % 2 == 1){int x = p + m*(i - 1);char n = (x - 1) % 26 + 65;cout << n;}else{int x = (m - p + 1) + m*(i - 1);char n = (x - 1) % 26 + 65;cout << n;}}cout << endl;}}return 0; }

總結(jié)

以上是生活随笔為你收集整理的## 弱鸡的第二次线上赛总结(TKK18no.4)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。