赞
踩
目录
题目来源:
- #include<iostream>
- using namespace std;
- int main()
- {
- for (int i = 0; i < 82.3 / 2.3; i++)
- {
- for (int j = 0; j < 82.3/1.9; j++)
- {
- if (2.3 * i + 1.9 * j == 82.3)
- {
- cout << i << endl;
- return 0;
- }
- }
- }
- }
解析:
- #include<iostream>
- #include<cmath>
- using namespace std;
-
- int main()
- {
- //计算对折拐弯处数目(等比公式推导)
- int a = pow(2,10)-1;
- //无对折情况下数目
- int b = pow(2,11);
- //最后面条数目
- cout << b-a;
- return 0;
- }
- #include<iostream>
- using namespace std;
- int ans;
-
- void dfs(int x, int y, int z)
- {
- if (x < 0 || y < 0) return;
-
- if (x == 0 && y == 1 && z == 1) ans++;
-
- if (x > 0) dfs(x - 1, y, z * 2);
- if (y > 0) dfs(x, y - 1, z - 1);
- }
-
- int main()
- {
- dfs(5, 10, 2);
-
- cout << ans;
-
- return 0;
- }
- //计算个位
- int ge_wei(int a)
- {
- if(a % 2 == 0)
- return (a * 2) % 10;
- else
- return (a * 2 + 5) % 10;
- }
-
- //计算进位
- int jin_wei(char* p)
- {
- char* level[] = {
- "142857",
- "285714",
- "428571",
- "571428",
- "714285",
- "857142"
- };
-
- char buf[7];
- buf[6] = '\0';
- strncpy(buf,p,6);
-
- int i;
- for(i=5; i>=0; i--){
- int r = strcmp(level[i], buf);
- if(r<0) return i+1;
- while(r==0){
- p += 6;
- strncpy(buf,p,6);
- r = strcmp(level[i], buf);
- if(r<0) return i+1;
- ______________________________; //填空
- }
- }
-
- return 0;
- }
-
- //多位数乘以7
- void f(char* s)
- {
- int head = jin_wei(s);
- if(head > 0) printf("%d", head);
-
- char* p = s;
- while(*p){
- int a = (*p-'0');
- int x = (ge_wei(a) + jin_wei(p+1)) % 10;
- printf("%d",x);
- p++;
- }
-
- printf("\n");
- }
-
- int main()
- {
- f("428571428571");
- f("34553834937543");
- return 0;
- }
-
解析:
函数名已经写得很清楚了:进位
既然有进那么就有不进位:答案为:
if(r>0) return i;
2014年第五届C/C++ B组蓝桥杯省赛真题_元气算法的博客-CSDN博客
- #include<iostream>
- #include<cmath>
-
- using namespace std;
-
- int main()
- {
- int cnt = 0;
- for(int a = 1; a < 10; a++)
- {
- for(int b = 1; b < 10; b++)
- {
- //满足分子分母不同
- if(a!=b)
- for(int c = 1; c < 10; c++)
- {
- for(int d = 1; d < 10; d++)
- {
- if(c!=d)
- {
- //浮点数判断相等
- if(fabs(a*c*1.0/(b*d)-(a*10.0+c)/(b*10+d))<1e-5)
- {
- cnt++;
- }
- }
- }
- }
- }
- }
- cout<< cnt <<endl;
- return 0;
- }
解析:
- #include <iostream>
- #include <algorithm>
- using namespace std;
-
- int main()
- {
- int a[9] = {2, 4, 5, 6, 7, 9, 10, 11, 12};
-
- do
- {
- int L1 = 1 + a[0] + a[3] + a[5];
- int L2 = 1 + a[1] + a[4] + a[8];
- int L3 = a[5] + a[6] + a[7] +a[8];
- int L4 = 8 + a[0] + a[1] + a[2];
- int L5 = 8 + a[3] + a[6] + 3;
- int L6 = a[2] + a[4] + a[7] + 3;
-
- if(L1 == L2 && L1 == L3 && L1 == L4 && L1 == L5 && L1 == L6) cout << a[3] << endl;
- }while(next_permutation(a, a + 9));
-
- return 0;
- }
- #include<iostream>
- #include<algorithm>
- using namespace std;
-
- const int N=55;
- int x[N];
- int n;
-
- int main()
- {
- cin>>n;
- for(int i=0;i<n;i++) cin>>x[i];
-
- int left=0,right=0;//左边向右走的:x[i]>0,且abs小于x[0],和右边向左走的:x[i]<0,且abs大于x[0]
- for(int i=1;i<n;i++)
- {
- if(abs(x[i])<abs(x[0]) && x[i]>0) left++;
- else if(abs(x[i])>abs(x[0]) && x[i]<0) right++;
- }
- if(x[0]>0 && right==0 || x[0]<0 && left==0) cout<<1<<endl;
- else cout<<left+right+1<<endl;
-
- return 0;
- }
- #include<iostream>
- #include<cstring>
- #include<algorithm>
-
- using namespace std;
-
- const int MOD = 1000000007, N = 55;
-
- int map[N][N];//地图的值
- int dp[N][N][13][14];//DP[A][B][C][D] AB横纵坐标 C数量 D最后一个为D的价值
-
- int main()
- {
- int n, m, k;//n m横纵数量 k K件宝物
- cin >> n >> m >> k;
-
- for (int i = 1; i <= n; i++)
- for (int j = 1; j <= m; j++)
- {
- cin >> map[i][j];
- map[i][j]++;
- }//读入地图宝物价值,为了方便初始下标判断,全加1
-
- dp[1][1][1][map[1][1]] = 1;//起始点选择 方案数1
- dp[1][1][0][0] = 1;//起始点不选 方案数1
-
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= m; j++)
- {
- if (i == 1 && j == 1)continue;//如果是起始点 跳过
-
- for (int u = 0; u < 13; u++)
- for (int v = 0; v < 14; v++)
- {
- int& val = dp[i][j][u][v];//引用 简化
-
- val = (val + dp[i - 1][j][u][v]) % MOD;//左边 不选
- val = (val + dp[i][j - 1][u][v]) % MOD;//上边 不选
-
- if (u > 0 && v == map[i][j])//最终的选择到了最大的价值宝物(因为题目递增),且有选择次数,则累加不同价值的子集
- //当前的方案数量=上一步的所有价值的方案数量之和
- {
- for (int c = 0; c < v; c++)//
- {
- val = (val + dp[i - 1][j][u - 1][c]) % MOD;//左边
- val = (val + dp[i][j - 1][u - 1][c]) % MOD;//上边
- }
- }
- }
- }
- }
-
- int res = 0;
- for (int i = 1; i <= 13; i++)res = (res + dp[n][m][k][i]) % MOD;//总方案数量等于当前数量下所有价值的数量总和
- cout << res;
- return 0;
- }
解析:
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- const int N = 1000010;
- int n;
- long long a[N], tr[N], b[N];
-
- int lowbit(int x)
- {
- return x & -x;
- }
-
- void add(int x, int y)
- {
- for (int i = x; i < N; i += lowbit(i)) tr[i] += y;
- }
-
- int query(int x)
- {
- int ans = 0;
- for (int i = x; i; i -= lowbit(i)) ans += tr[i];
- return ans;
- }
-
- int main()
- {
- cin >> n;
- for (int i = 1; i <= n; i++)
- {
- cin >> a[i];
- a[i]++;
- }
-
- for (int i = 1; i <= n; i++)
- {
- add(a[i], 1);
- b[i] = i - query(a[i]);
- }
-
- memset(tr, 0, sizeof tr);
-
- for (int i = n; i >= 1; i--)
- {
- add(a[i], 1);
- b[i] += query(a[i] - 1);
- }
-
- long long res = 0;
-
- for (int i = 1; i <= n; i++)
- {
- res += (1 + b[i]) * b[i] / 2;
- }
-
- cout << res << endl;
-
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。