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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

solo01

發布時間:2024/3/13 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 solo01 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

數字游戲

Kimi和Sunny在玩一個數字游戲。游戲規則如下:
(1) 每個人各隨機抽取n張寫有1-100中某個正整數的卡片,假定卡片的數量不限,隨機抽取的數字中可能會有重復數字。
(2) 每一輪游戲雙方各亮出一張卡片,卡片上數字大者加1分,數字小者不扣分,相等則都不加分。
(3) n輪游戲后得分高者獲勝。
Kimi知道Sunny也很聰明,要想獲勝不那么容易。他只想知道在兩個人的數字都已經給定的情況下,他最多可以拿到多少分。
現在請你編寫一個程序幫幫Kimi。

輸入

單組輸入。
第1行輸入一個正整數n表示每人隨機抽取的卡片的數量,n不超過1000。
第2行包含n個1-100之間的正整數表示Kimi抽到的卡片上的數字,兩兩之間用英文空格隔開。
第3行包含n個1-100之間的正整數表示Sunny抽到的卡片上的數字,兩兩之間用英文空格隔開。

輸出

輸出Kimi最多可以得到的分數。

樣例輸入
5
3 4 5 5 2
1 4 5 3 2
樣例輸出
4

#include<bits/stdc++.h> using namespace std;int a[1001]; int b[1001];int main(){//這個題,對于kimi的每一張牌,盡量去找到比它小的牌就好,也就是說,盡量去滿足他得分的條件,//要排個序//沒想到int n;cin>>n;for(int i=0;i<n;i++){cin>>a[i];}for(int i=0;i<n;i++){cin>>b[i];}sort(a,a+n);sort(b,b+n);int mark=0,i=0,j=0;while(i<n){if(a[i]>b[j]){mark++;i++;j++;} elsei++;}cout<<mark<<endl;//system("pause");return 0; }

Morse Code

題目描述
Morse code, also known as Morse code, is a kind of on-off signal code, which expresses different English letters, numbers and punctuation symbols through different order. It was invented in 1837 and is an early form of digital communication. Different from modern digital communication, Morse code consists of two basic signals: short point signal “?” and reading “drop”; Keep the long signal “-” for a certain time and read “Da”.
In order to increase the difficulty of decoding, the communication group decided that there must be more than one short message number “?” between every two long signals “-” in Morse code of any length, otherwise it will be regarded as invalid code. For example, the number of schemes of an effective Morse code with a length of 3 is 5, which are respectively: - ? -, - ? ?, ? -, ? ? -, ? ? ?.
Here is the length of Morse code. Do you know the number of effective Morse code schemes?

輸入
The input has multiple cases (no more than 100) of test data.
Each test case occupies one line, which is a positive integer N(1 ≤ N ≤ 1000000) represents the length of the Morse code given to you.
The end of input will be represented by a line of test case where A equal to 0. This test case should not be processed.

輸出
Each test case outputs a line, which is an integer, that is, the modular result of 2021 by the number of schemes of effective Morse code.

樣例輸入
2
3
0
樣例輸出
3
5

別被英文唬住了,就是個遞推規律題,記得取模

#include<bits/stdc++.h> using namespace std;long long a[1000001];int main(){int n;a[1]=2;a[2]=3;for(int i=3;i<=1000000;i++){a[i]=a[i-1]+a[i-2];a[i]=a[i]%2021;}while(cin>>n&&n){cout<<a[n]<<endl;} system("pause");return 0; }

X星危機

最近宇宙局勢很亂,X星人感受到了來自Y星的巨大威脅。
X星人決定修建一系列防御工事,X星人首先在一張矩形地圖上設計防御工事。
在該地圖上,每一個小格稱為一個單元。沒有修建防御工事的單元用“*”表示,修建了防御工事的單元用“@”表示。多個相鄰的防御工事單元(只考慮上、下、左、右相鄰)可以連接到一起形成一個防御單元群(當然,也可能存在只有一個防御單元的防御單元群),X星人希望在每一個防御單元群中至少有一個這樣一個防御單元,它的上、下、左、右全部都是防御單元,以便用來做指揮部或者存放重要物資。
現在給你一張防御工事地圖,你能否編寫一個程序統計有多少個滿足要求的防御單元群?

`輸入
單組輸入。
第1行輸入兩個不超過1000的正整數m和n,表示矩陣的行和列,兩者之間用英文空格隔開。
接下來m行,每行包含n個’‘或’@‘,其中’‘表示非防御單元,’@'表示防御單元。

輸出
輸出兩個整數,分別為防御單元群的總個數和滿足要求的防御單元群的個數。其中,滿足要求的防御單元群是指在該防御單元群中至少存在一個防御單元,其上、下、左、右也是防御單元。

樣例輸入
5 5
@@@@
@***
**@@@
**@@@
@@@@@
樣例輸出
3 1

搜索題
dfs

#include<iostream> #include<cstring> using namespace std; char map[1001][1001]; int num[1001][1001]; int ans[1000000]; int mark=0,count=0; int n,m; int dir[][2]={{-1,0},{0,-1},{1,0},{0,1}};void dfs(int x,int y,int mark){int dx,dy;if(x<1||x>m||y<1||y>n)return;if(num[x][y]>0||map[x][y]!='@')return;num[x][y]=mark;for (int i=0;i<4;i++){dx=x+dir[i][0];dy=y+dir[i][1];dfs(dx,dy,mark);} }int main(){cin>>m>>n;for(int i=1;i<=m;i++){for(int j=1;j<=n;j++){cin>>map[i][j];}}for(int i=1;i<=m;i++){for(int j=1;j<=n;j++){if(num[i][j]==0&&map[i][j]=='@'){dfs(i,j,++mark);}}}for(int i=1;i<=m;i++){for(int j=1;j<=n;j++){if(num[i][j]!=0){bool flag=true;for (int k=0;k<4;k++){if(num[i+dir[k][0]][j+dir[k][1]]!=num[i][j]){flag=false;break;}}if(flag)ans[num[i][j]]=1;}}}for(int i=1;i<=mark;i++) if(ans[i]) count++;cout<<mark<<" "<<count<<endl;//system("pause");return 0; }

大佬的dfs:

#include<iostream> #include<cstring> using namespace std; char map[1001][1001]; bool vis[1001][1001]; int ans[1000000]; int mark=0,count=0; int n,m; int dir[][2]={{-1,0},{0,-1},{1,0},{0,1}};bool check(int x,int y){if(x<1||x>m||y<1||y>n||map[x][y]=='*')return false;return true; }int dfs(int x,int y){int res=0,k=0;int dx,dy;for (int i=0;i<4;i++){dx=x+dir[i][0];dy=y+dir[i][1];if(check(dx,dy)&&!vis[dx][dy]){vis[dx][dy]=true;res |=dfs(dx,dy);}if(check(dx,dy))k++;}if(k==4)res=1;return res; }int main(){cin>>m>>n;for(int i=1;i<=m;++i){scanf("%s",map[i]+1);}for(int i=1;i<=m;++i){for(int j=1;j<=n;++j){if(!vis[i][j]&&map[i][j]=='@'){mark++;count+=dfs(i,j);}}}cout<<mark<<" "<<count<<endl;//system("pause");return 0; }

tql。。。orz

bfs

#include<iostream> #include<queue> using namespace std; typedef pair<int,int>PII; char map[1001][1001]; bool vis[1001][1001];int mark=0,count=0; int n,m; int dir[][2]={{-1,0},{0,-1},{1,0},{0,1}};bool check(int x,int y){if(x<1||x>m||y<1||y>n||map[x][y]=='*')return false;return true; }int bfs(int x,int y){queue<PII>q;q.push({x,y});vis[x][y]=true;bool ok=false;while(!q.empty()){PII u=q.front();q.pop();int x=u.first;int y=u.second;int k=0;for (int i=0;i<4;i++){int dx=x+dir[i][0];int dy=y+dir[i][1];if(check(dx,dy)&&!vis[dx][dy]){q.push({dx,dy});vis[dx][dy]=true;}if(check(dx,dy))k++;}if(k==4)ok=true;}if(ok)return 1;else return 0; }int main(){cin>>m>>n;for(int i=1;i<=m;++i){scanf("%s",map[i]+1);}for(int i=1;i<=m;++i){for(int j=1;j<=n;++j){if(!vis[i][j]&&map[i][j]=='@'){mark++;count+=bfs(i,j);}}}cout<<mark<<" "<<count<<endl;//system("pause");return 0; }

后續再補充了,得去學搜索了

總結

以上是生活随笔為你收集整理的solo01的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。