河南省第十届大学生程序设计竞赛 A,B,C,D,F,G,H 题解
生活随笔
收集整理的這篇文章主要介紹了
河南省第十届大学生程序设计竞赛 A,B,C,D,F,G,H 题解
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
H: Intelligent Parking Building
時間限制:?1 Sec??內(nèi)存限制:?128 MB提交:?22??解決:?20
[提交][狀態(tài)][討論版]
題目描述
There is a new revolution in the parking lot business: the parking ?building. The concept is simple: you drive your car into the elevator at the entrance of the building, and the elevator and conveyor belts drag the car to an empty parking spot, where the car remains until you pick it up. When you return, the elevator and conveyor belts move your car back to the entrance and you’re done.The layout of the building is simple. There is one central elevator that transports the cars between the different floors. On each floor there is one giant circular conveyor belt on which the cars stand. This belt can move in clockwise and counterclockwise direction. When the elevator arrives on a floor, it becomes part of the belt so that cars can move through it.
At the end of the day the building is usually packed with cars and a lot of people come to pick them up. Customers are processed in a first come first serve order: the elevator is moved to the floor of the first car, the conveyor belt moves the car on the elevator, the elevator is moved down again, and so on. We like to know how long it takes before the last customer gets his car. Moving the elevator one floor up- or downwards takes 10 seconds and moving ?the conveyor belt one position in either direction takes 5 seconds.?
輸入
On the first line one positive number: the number of testcases, at most 30. ?Each test case specifies:?One line with two integers h and l with 1 ≤ h ≤ 50 and 2 ≤ l ≤ 50: the height of the parking tower and the length of the conveyor belts.
?h lines with l integers: the initial placement of the cars. The jth number on the ith line describes the jth position on the ith floor. This number is ?1 if the position is empty, and r if the position is occupied by the rth car to pick up. The positive numbers form a consecutive sequence from 1 to the number of cars. The entrance is on the first floor and the elevator (which is initially empty) is in the first position. There is at least one car in the parking tower.
輸出
For each test case generate a single line containing a single integer ?that is the number of seconds before the last customer is served.樣例輸入
3 1 5 1 -1 -1 -1 2 1 5 2 - 1 -1 -1 1 3 6 -1 5 6 -1 -1 3 -1 -1 7 -1 2 9 -1 10 4 1 8 -1樣例輸出
5 10 320模擬: 電梯 上下來回一層20s ?傳送帶左右 移動一個位置 5s 記錄 上一次電梯位置: #include<iostream> #include<stdio.h> #include<string.h> #include<cmath> #include<cmath> #include<set> using namespace std; const int N=260;struct Fuck{int x,y; }a[N];int b[56];//每層電梯所對車位的編號int main() {int n,h,l,maxx;while(cin>>n){while(n--){memset(b,0,sizeof(b));//初始車位編號是0的與電梯相鄰scanf("%d%d",&h,&l);maxx=0;for(int i=0;i<h;i++)for(int j=0;j<l;j++){int m;cin>>m;if(m!=-1){a[m].x=i;a[m].y=j;maxx=max(maxx,m);}}int ant=0;for(int i=1;i<=maxx;i++)//模擬一個一個出{int cen=a[i].x;//i的所在的層數(shù)int num=a[i].y;//所在的編號ant+=2*cen*10;// cout<<ant<<endl;ant+=5*min(abs(num-b[cen]),l-abs(num-b[cen]));//逆時針 順時針//cout<<abs(num-b[i])<<" "<<l-abs(num-b[i])<<endl;b[cen]=num;//cout<<"B"<<b[i]<<endl;}cout<<ant<<endl;}}return 0; }
問題 B: 情報傳遞
時間限制:?2 Sec??內(nèi)存限制:?128 MB提交:?35??解決:?17
[提交][狀態(tài)][討論版]
題目描述
抗日戰(zhàn)爭時期,在國共合作的大背景下,中共不斷發(fā)展壯大,其情報工作也開始由獲取警報性、保衛(wèi)性信息,向獲取軍政戰(zhàn)略性情報轉(zhuǎn)變。各系統(tǒng)情報組織遵循"蔭蔽精干,長期埋伏,積蓄力量,以待時機"的隱蔽戰(zhàn)線工作方針,開展了卓有成效的情報工作。***特科組是中共情報工作的一個杰出范例,它以點為主、系統(tǒng)延伸、分散輻射的力量格局,異地領(lǐng)導、分頭派遣、單線聯(lián)系的組織形式。以打入、拉出、統(tǒng)戰(zhàn)聯(lián)絡(luò)、內(nèi)線為主的工作方式,形成了一個傳遞信息隱蔽、效用及時、形式多樣的情報網(wǎng)絡(luò)。
***特科組的情報人員共有N人,其代號分別為0,1,……,N-1。 0號是最高領(lǐng)導人,特工之間有一套嚴格的單線聯(lián)絡(luò)程序,即,每個特工人員只有一個上線,他獲得的情報需層層上傳遞到0號手里,由0號發(fā)報出去。
特工i在傳遞情報時,若通往到0號的通道尚未建立,則需要建立一級級單線通道;若他的上線已建立好通道,只需建立兩人通道,信息發(fā)送給上線;依次類推。若特工i已建立好到0號的通道,則直接發(fā)出情報。日偽統(tǒng)治中心南京,既是情報來源豐富的地方,又是特工人員活動最危險的地方。因此,一旦某個特工處于不安全狀態(tài),他必須馬上撤離,同時他的所有下線(處在通道上的一級級下線)也一同撤離。
已知***特科組的組織結(jié)構(gòu),你的任務(wù)是計算,當某特工i需要發(fā)送情報時,最少需要建立幾個情報人員的通道;當某特工i處于不安全狀態(tài)時,最少需要撤離多少人員。
輸入
第一行一個整數(shù): ?N ? ? ? ? ? ( 1≤N ≤5060 )接下來一行有N-1 個整數(shù), ?A1 A2 ……An-1 ?,其中Ai是編號i的上線。
下一行一個整數(shù): ?M ? ? ? ? 表示有M個狀態(tài),( 1≤M ≤5060 )
接下來有M行 :有兩種形式: ?Send i ? ?特工i處于要發(fā)送情報狀態(tài);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Danger i ?特工i處于不安全狀態(tài)
輸出
輸出占M行 ,對于Send i,輸出最少需要建立通道的情報人員數(shù),若特工i處于通道線上,輸出0;對于Danger i,輸出最少需要撤離多少人員,若特工i不處于通道線上,則輸出0.樣例輸入
10 0 1 2 1 3 0 0 3 2 10 Send 0 Send 3 Danger 2 Send 7 Send 5 Send 9 Danger 9 Send 4 Send 1 Send 9樣例輸出
1 3 2 1 3 1 1 1 0 1提示
情況可分為 類似于一個 樹, 每個人有上級和下級, ? 傳遞 找上級看是否 未標記,未標記+1 , 向下查詢,如果標記則+1注意要點: 1 : ? 0 也需要傳遞 2: ?當前情況與上一次有關(guān)
向上簡單 數(shù)組存上級 查詢上去; 向下 可以用dfs 或者bfs 我這里用的是 鏈表 vector+ queue 隊列 ?鏈表存 每個數(shù)的下級; ?用隊列 來進行 查詢 循環(huán)
代碼: #include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <queue> #include <stack> #include <stdlib.h> #include <list> #include <map> #include <set> #include <bitset> #include <vector> #define mem(a,b) memset(a,b,sizeof(a)) #define findx(x) lower_bound(b+1,b+1+bn,x)-b #define FIN freopen("input.txt","r",stdin) #define FOUT freopen("output.txt","w",stdout) #define S1(n) scanf("%d",&n) #define SL1(n) scanf("%I64d",&n) #define S2(n,m) scanf("%d%d",&n,&m) #define SL2(n,m) scanf("%I64d%I64d",&n,&m) #define Pr(n) printf("%d\n",n)using namespace std; typedef long long ll; const double PI=acos(-1); const int INF=0x3f3f3f3f; const double esp=1e-6; const int maxn=1e6+5; const int MOD=1e9+7; const int mod=1e9+7; int dir[5][2]={0,1,0,-1,1,0,-1,0};int vis[maxn]; int boss[maxn]; vector<int> lis[6000]; void find_up(int x) {int ans=0;while(!vis[x]){ans++;vis[x]=1;x=boss[x];}cout<<ans<<endl; }void find_down(int x) {queue<int> Q;int ans=0;Q.push(x);if(vis[x]){//ans++;vis[x]=0;while(!Q.empty()){int t=Q.front();Q.pop();ans++;for(int i=0;i<lis[t].size();i++){if(vis[lis[t][i]]==1){//ans++;vis[lis[t][i]]=0;Q.push(lis[t][i]);}}}}cout<<ans<<endl;} int main() {int n;//FIN;while(~S1(n)){mem(vis,0);mem(lis,0);int x;for(int i=1;i<n;i++){S1(x);boss[i]=x;//上lis[x].push_back(i);//下}int m;S1(m);char str[10];while(m--){scanf("%s %d",str,&x);if(str[0]=='S')find_up(x);elsefind_down(x);}}return 0; }
123
問題 A: 諜報分析
時間限制:?1 Sec??內(nèi)存限制:?128 MB提交:?19??解決:?18
[提交][狀態(tài)][討論版]
題目描述
“八一三”淞滬抗戰(zhàn)爆發(fā)后,***幾次準備去上海前線視察和指揮作戰(zhàn)。但都因為寧滬之間的鐵路和公路遭到了敵軍的嚴密封鎖,狂轟濫炸,一直未能成行。?***特科組織,其主要任務(wù)是保衛(wèi)***的安全,了解和掌握敵方的動向。經(jīng)過一段時間的監(jiān)聽,諜報組獲取了敵方若干份密報,經(jīng)過分析,發(fā)現(xiàn)密文中頻繁出現(xiàn)一些單詞,情報人員試圖從單詞出現(xiàn)的次數(shù)中,推出敵軍的行動計劃。
請你編程,快速統(tǒng)計出頻率高的前十個單詞。
輸入
密文是由英語單詞(小寫字母)組成,有若干段。單詞之間由一個或多個空格分開,自然段之后可以用一個“,”或“。”表示結(jié)束。整個內(nèi)容的單詞數(shù)量不超過10000,不同的單詞個數(shù)不超過500.輸出
輸出占10行,每行一個單詞及出現(xiàn)的次數(shù),中間一個空格。要求按頻率降序輸出,出現(xiàn)次數(shù)相同的單詞,按字典序輸出。樣例輸入
shooting is at shanghai station. shooting must be carried out. shooting shooting. shanghai station must be surrounded, at least a team of one hundred soldiers to fight. twenty five soldiers shooting in the north, twenty five soldiers shooting in the south, twenty five soldiers shooting in the east, twenty five soldiers shooting in the west.樣例輸出
shooting 8 soldiers 5 five 4 in 4 the 4 twenty 4 at 2 be 2 must 2 shanghai 2提示
水題:
#include<iostream> #include<algorithm> #include<string> #include<set> #include<map> #include<stdio.h> using namespace std; struct Fuck{string str;int num; }c[10004];int cmp(Fuck a,Fuck b) {if(a.num==b.num)return a.str<b.str;return a.num>b.num; } using namespace std; int main() {string str,str1;map<string,int>mymap;mymap.clear();int l=0;while(cin>>str){int len=str.length();if(str[len-1]=='.'||str[len-1]==',')str1=str.substr(0,len-1);elsestr1=str;l++;mymap[str1]++;}map<string,int>::iterator it;int i=0;for(it=mymap.begin();it!=mymap.end();it++){c[i].str=it->first;c[i].num=it->second;i++;}int len=i;sort(c,c+len,cmp);for(int i=0;i<10;i++)cout<<c[i].str<<" "<<c[i].num<<endl;return 0; }問題 C: 最小密鑰
時間限制:?1 Sec??內(nèi)存限制:?128 MB提交:?26??解決:?22
[提交][狀態(tài)][討論版]
題目描述
在中國近代史上,暫編***軍絕對是一支能打硬仗,大名鼎鼎的行動部隊。“一二八”上海抗戰(zhàn),暫編***軍就曾打得小日本四易主帥。*月**號,暫編***軍計劃組成一個行動大隊,派出N名隊員潛伏在***地,發(fā)動一次大規(guī)模的巷戰(zhàn)行動。每名隊員有自己的代號Ai,為了更好的配合作戰(zhàn),他們需要獲得一個密鑰Key, ?然后各自迅速移動到Ai ?MOD ?Key位置,**時刻一起開戰(zhàn)。
作戰(zhàn)方案已經(jīng)定好,你能幫***行動大隊快速找個滿足條件的最小密鑰Key嗎?
MOD表示取模運算,要求不能有多名隊員待在同一個位置。
輸入
第一行:T表示以下有T組測試數(shù)據(jù)(1≤T≤5)對每組數(shù)據(jù),
第一行:N表示行動人員數(shù)(1<=N<=3000)
接下來一行有N個整數(shù),分別表示每個隊員的代號Ai(1<=Ai<=20000)
輸出
對每組測試數(shù)據(jù),輸出占一行,一個整數(shù) Key.樣例輸入
2 3 1 2 3 5 4 6 9 10 13樣例輸出
3 8#include<iostream> #include<cstdio> #include<cstring>using namespace std;int main() {int n,a[3005],T,vis[20005];scanf("%d",&T);while(T--){memset(vis,0,sizeof(vis));int flag,mixx=-1;scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d",&a[i]);if(a[i]>mixx)mixx=a[i];}for(int i=n;i<=mixx;i++){memset(vis,0,sizeof(vis));flag=0;for(int j=0;j<n;j++){if(vis[a[j]%i]==0){vis[a[j]%i]=1;}else{flag=1;break;}}if(!flag){printf("%d\n",i);break;}}}return 0; }
年終獎金
時間限制:?2 Sec??內(nèi)存限制:?128 MB提交:?37??解決:?23
[提交][狀態(tài)][討論版]
題目描述
***公司承接了N個項目需要年底完成,每個項目有一定的難度系數(shù)。由于項目太多了,需要招聘大量的技術(shù)人員。要求每個技術(shù)人員至少完成K個項目。考慮到有些項目之間相似性以及項目的難易程度,為了避免某些員工只挑選輕松項目,CEO提出了一個獎勵機制,當技術(shù)人員完成分配給他的任務(wù)后,年終可以得到一筆獎金,其得到的酬金將是C + (Tmax–Tmin)2。其中,Tmax表示所做項目的最大的難度系數(shù),Tmin是難度系數(shù)的最小值。
你能否計算一下,為了完成所有項目,***公司年終至少需要支付多少酬金?
輸入
輸入有多組測試數(shù)據(jù)。對每組測試數(shù)據(jù):第一行:NKC(1<=N,K<=1001<=C<=5000)
第二行N個正整數(shù)分別描述N個項目的難度系數(shù)。(1<=難度系數(shù)<=10000)
輸出
對每組測試數(shù)據(jù):輸出占一行,一個整數(shù)。即,***公司年終至少需要支付的酬金數(shù)。樣例輸入
2 1 1 2 4 10 2 3 1 4 10 3 10 1 8 3 8 3樣例輸出
2 13提示
第一組測試數(shù)據(jù),如果一個人完成,酬金為1 + (4–2)2?= 5;如果分給兩個人去完成,收費為1 + 1 = 2。
DP最少k 個任務(wù), 排下序, ?然后 從k- n ?判斷 ?是否要讓他來做 這個任務(wù), 或者 ?全部工作讓一個人來做;
dp 存的是時間
#include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <queue> #include <stack> #include <stdlib.h> #include <list> #include <map> #include <set> #include <bitset> #include <vector> #define mem(a,b) memset(a,b,sizeof(a)) #define findx(x) lower_bound(b+1,b+1+bn,x)-b #define FIN freopen("input.txt","r",stdin) #define FOUT freopen("output.txt","w",stdout) #define S1(n) scanf("%d",&n) #define SL1(n) scanf("%I64d",&n) #define S2(n,m) scanf("%d%d",&n,&m) #define SL2(n,m) scanf("%I64d%I64d",&n,&m) #define Pr(n) printf("%d\n",n)using namespace std; typedef long long ll; const double PI=acos(-1); const int INF=0x3f3f3f3f; const double esp=1e-6; const int maxn=1e6+5; const int MOD=1e9+7; const int mod=1e9+7; int dir[5][2]={0,1,0,-1,1,0,-1,0};ll inv[maxn*2],fac[maxn]; ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;} ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;} ll lcm(ll a,ll b){ return b/gcd(a,b)*a;} ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;} void INV(){inv[1] = 1;for(int i = 2; i < maxn; i++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;} void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);}} void Fac(){fac[0]=1;for(int i=1;i<=maxn;i++)fac[i]=(fac[i-1]*i)%MOD;} ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;} ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;} ll inv2(ll b){return qpow(b,MOD-2);} ll cal(ll m,ll n){if(m<n)return 0;return (fac[m]*inv[fac[n]]%MOD)%MOD*inv[fac[m-n]]%MOD;} ll cals(ll m,ll n){if(m<n)return 0;return (fac[m]*inv1(fac[n])%MOD)%MOD*inv1(fac[m-n])%MOD;}int dp[maxn],a[maxn]; int main() {int n,k,c;while(~scanf("%d %d %d",&n,&k,&c)){mem(a,0);for(int i=1;i<=n;i++)scanf("%d",&a[i]);for(int i=1;i<=maxn;i++)dp[i]=INF;dp[0]=0;sort(a+1,a+n+1);for(int i=1;i<=n;i++)for(int j=1;j<=i-k+1;j++){if(j>=k||j==1)dp[i]=min((a[i]-a[j])*(a[i]-a[j])+c+dp[j-1],dp[i]);}cout<<dp[n]<<endl;}return 0; }123
問題 F: Binary to Prime
時間限制:?1 Sec??內(nèi)存限制:?128 MB提交:?30??解決:?22
[提交][狀態(tài)][討論版]
題目描述
To facilitate the analysis of ?a DNA sequence, ?a DNA sequence is represented by a binary ?number. The group of ?DNA-1 has discovered a great new way . ?There is a certain correlation between binary number and prime number. Instead of using the ordinary decadic numbers, they use prime base numbers. Numbers in this base are expressed as sequences of zeros and ones similarly to the binary numbers, but the weights of bits ?in the representation are not powers of two, but the elements of the primes ?( 2, 3, 5, 7,... ).?For example ?01101 , ie. 2+5+7=14?
Herefore, it is necessary to convert the binary number to the sum of prime numbers。
輸入
The input consists of several instances, each of them consisting of a single line. Each line of the input contains a 01 string, length of not more than 150. ?The end of input is not marked in any special way.輸出
For each test case generate a single line containing a single integer , The sum of the primes.樣例輸入
000010 0011 11001樣例輸出
3 5 20#include<iostream> #include<cstdio> #include<cstring>using namespace std;int main() {int a[1005]={0},c[200];for(int i=2;i<1000;i++){for(int j=i+i;j<1000;j+=i){a[j]=1;}}int k=0;for(int i=2;i<1000;i++){if(a[i]==0){c[k++]=i;}}char b[200];while(cin>>b){int sum=0;int i;int n=strlen(b);for(int j=n-1;j>=0;j--)if(b[j]=='1'){sum+=c[n-j-1];}printf("%d\n",sum);}return 0; }
?Plumbing the depth of lake
時間限制:?1 Sec??內(nèi)存限制:?128 MB提交:?22??解決:?15
[提交][狀態(tài)][討論版]
題目描述
There is a mysterious lake in the north of Tibet. As the sun shines, the surface of the lake is colorful and colorful. The lake was unfathomable in rainy weather. ?After the probe, ?It has an interesting bottom in that it is full of little hills and valleys. . Scientists wonders how deep the bottom of the lake is.Scientists use the most advanced radar equipment to detect the bottom of the lake. It is the discovery that the deepest part is relatively flat. Thet want to know the largest depth number only if it is verified by the fact that the same depth appears in an adjacent reading.
To facilitate computing, scientists have put the lake as M * N grids . The depth ?reading of each grid is already known. some readings might be 0-- It's a small island on the lake.
?
Find the greatest depth that appears in at least two 'adjacent'readings (where 'adjacent' means in any of the potentially eight squares that border a square on each of its sides and its diagonals). The lake has at least one pair of positive, adjacent readings.
輸入
The first line of the input contains one integers T, which is the nember of ?test cases (1<=T<=5). ?Each test case specifies:* Line 1: Two space-separated integers: M and N ? (1 ≤ M, ?N ≤ 50)
* Lines 2..M+1: Line i+1 contains N space-separated integers that ?represent the depth of the lake across row i: Dij ? ?(0 <= Dij <=1,000,000);
輸出
For each test case generate a single line: ?a single integer that is the depth of the lake determined.樣例輸入
1 4 3 0 1 0 1 2 0 1 5 1 2 3 4樣例輸出
1#include<iostream> #include<cstdio> #include<cstring>using namespace std; int tx[8]={1,-1,0,0,1,1,-1,-1}; int ty[8]={0,0,1,-1,1,-1,1,-1};int main() {int m,n,a[55][55],maxx,T;scanf("%d",&T);while(T--){scanf("%d%d",&m,&n);maxx=-1;for(int i=1;i<=m;i++){for(int j=1;j<=n;j++){scanf("%d",&a[i][j]);}}for(int i=1;i<=m;i++){for(int j=1;j<=n;j++){for(int k=0;k<8;k++){int xx=i+tx[k];int yy=j+ty[k];if(a[i][j]==a[xx][yy]){if(a[i][j]>maxx){maxx=a[i][j];}break;}}}}printf("%d\n",maxx);}return 0; }
123
轉(zhuǎn)載于:https://www.cnblogs.com/sizaif/p/9078477.html
《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的河南省第十届大学生程序设计竞赛 A,B,C,D,F,G,H 题解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 多线程必须用到的线程池(什么时候用多线程
- 下一篇: Effective MySQL之深入解析