第六屆藍橋杯2015-省賽-C語言大學B組 個人題解

來源:互聯網
上載者:User

標籤:

題目串連:http://course.baidu.com/view/2d86a6c1960590c69fc37622.html

1,獎券數目52488

#include <iostream>using namespace std;bool isOK(int a){while(a){if(a%10==4) return false;a /= 10;}return true;}int main(){int ans = 0;for(int i=10000; i<=99999; i++){if(isOK(i)){ans++;}}cout << ans << endl;return 0;}

2,星系炸彈2017-08-05

#include <iostream>using namespace std;bool jwd(int y, int m, int d){if(m==4 || m==6 || m==9 || m==11){return d > 30;}else if(m==2){if((y%4==0 && y%100!=0) || (y%400==0)){return d > 29;}else{return d > 28;}}else{return d > 31;}}int main(){int y, m, d, ct = 1000;y = 2014;m = 11;d = 9;while(ct--){d++;if(jwd(y, m, d)){d = 1;m++;}if(m>12){m = 1;y++;}}cout << y << "-" << m << "-" << d << endl;return 0;}

3,三羊獻瑞1085

暴力枚舉做的

4,格子中輸出(width-2-strlen(buf))/2,"",buf,width-2-(width-2-strlen(buf))/2-strlen(buf),""

5,九數組分數{t=x[k]; x[k]=x[i]; x[i]=t;}

6,加法變乘法16

#include <iostream>using namespace std;int main(){int a, b, sum = 1225;for(a=1; a<=49; a++){for(b=a+2; b<=49; b++){int k = sum - 2*a - 1 - 2*b - 1 + a*a + a + b*b + b;if(k == 2015){cout << a << endl;}}}return 0;}
7,牌型種數3598180

#include <iostream>using namespace std;int dfs(int pai, int ct){if(pai == 13){return ct <= 4;}int res = 0;res += dfs(pai+1, ct);if(ct >= 1)res += dfs(pai+1, ct-1);if(ct >= 2)res += dfs(pai+1, ct-2);if(ct >= 3)res += dfs(pai+1, ct-3);if(ct >= 4)res += dfs(pai+1, ct-4);return res;}int main(){cout << dfs(1, 13) << endl;return 0;}

8,移動距離

#include <iostream>using namespace std;int main(){int w, n, m;int x1, y1, x2, y2;cin >> w >> m >> n;x1 = (m + w - 1) / w;if(x1%2==1){y1 = m - (x1 - 1) * w;}else{y1 = w - (m - (x1 - 1) * w) + 1;}x2 = (n + w - 1) / w;if(x2%2==1){y2 = n - (x2 - 1) * w;}else{y2 = w - (n - (x2 - 1) * w) + 1;}int ans = 0;if(x1 > x2){ans += x1 - x2;}else{ans += x2 - x1;}if(y1 > y2){ans += y1 - y2;}else{ans += y2 - y1;}cout << ans << endl;return 0;}
9,壘骰子
#include <iostream>#include <cstring>using namespace std;const int MOD = 1000000007;bool ok[7][7];__int64 dp[110000][7];__int64 dfs(int n,int pre){if(n==0){return dp[n][pre] = 1;}if(dp[n][pre]!=-1) return dp[n][pre];__int64 res = 0;for(int i=1; i<=6; i++){if(ok[pre][i])res += dfs(n-1, i)*4;}return dp[n][pre] = res%MOD;}int main(){int n, m, a, b;cin >> n >> m;memset(dp, -1, sizeof (dp));for(int i=0; i<=6; i++){for(int j=0; j<=6; j++){ok[i][j] = true;}}while(m--){cin >> a >> b;ok[a][b] = ok[b][a] = false;}cout << dfs(n, 0) << endl;return 0;}

這個只能過60%,數學不會沒辦法,看大神的題解好像是要矩陣快速乘法

10,生命之樹
#include <iostream>#include <stdio.h>#include <vector>#include <cstring>using namespace std;vector<int>G[100010];int val[100010];bool use[100010];__int64 ans;__int64 dfs(int xb){use[xb] = true;__int64 res = val[xb];for(int i=0; i<G[xb].size(); i++){ int k = G[xb][i]; if(!use[k]) { int b = dfs(k); if(b>0) res += b; }}if(ans < res){ans = res;}return res;}int main(){int n, i, a, b;scanf("%d", &n);for(i=1; i<=n; i++){scanf("%d", &val[i]);G[i].clear();}for(i=1; i<n; i++){scanf("%d %d",&a, &b);G[a].push_back(b);G[b].push_back(a);}memset(use, 0, sizeof (use));ans = val[1];dfs(1);cout << ans << endl;return 0;}

藍橋杯已經算是告一段落咯,數學題目什麼都還不會,得要加油學習了!






第六屆藍橋杯2015-省賽-C語言大學B組 個人題解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.