1042 数字0-9的数量
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 
给出一段区间a-b,统计这个区间内0-9出现的次数。

 
比如 10-19,1出现11次(10,11,12,13,14,15,16,17,18,19,其中11包括2个1),其余数字各出现1次。
Input
  1. 两个数a,b1 <= a <= b <= 10^18)
Output
  1. 输出共10行,分别是0-9出现的次数
Input示例
  1. 10 19
Output示例
  1. 1
  2. 11
  3. 1
  4. 1
  5. 1
  6. 1
  7. 1
  8. 1
  9. 1
  10. 1
    这道题和有一题统计数字,差不多的,只不过这里统计所有,0的细节稍微特殊考虑一下。
  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<cmath>
  5. #include<cstring>
  6. using namespace std;
  7.  
  8. typedef long long LL;
  9.  
  10. LL st,ed,ans[]={};
  11.  
  12. LL make(LL num,int now)
  13. {
  14. LL res=,tail=,mi=;
  15. if (num<&&now==) return ;
  16. while (num!=)
  17. {
  18. if (now==&&num<) break;
  19. int x=num%;
  20. num/=;
  21. res+=(num-(now==))*mi;
  22. if (x>now) res+=mi;
  23. if (x==now) res+=tail+;
  24. tail=(LL)x*mi+tail,mi*=;
  25. }
  26. return res;
  27. }
  28. int main()
  29. {
  30. scanf("%lld%lld",&st,&ed);
  31. for (int i=;i<=;i++)
  32. {
  33. ans[i]=make(ed,i)-make(st-,i);
  34. printf("%lld\n",ans[i]);
  35. }
  36. }
1050 循环数组最大子段和
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题
N个整数组成的循环序列a[1],a[2],a[3],…,a[n],求该序列如a[i]+a[i+1]+…+a[j]的连续的子段和的最大值(循环序列是指n个数围成一个圈,因此需要考虑a[n-1],a[n],a[1],a[2]这样的序列)。当所给的整数均为负数时和为0。
例如:-2,11,-4,13,-5,-2,和最大的子段为:11,-4,13。和为20。
 
Input
  1. 1行:整数序列的长度N2 <= N <= 50000)
  2. 2 - N+1行:N个整数 (-10^9 <= S[i] <= 10^9)
Output
  1. 输出循环数组的最大子段和。
Input示例
  1. 6
  2. -2
  3. 11
  4. -4
  5. 13
  6. -5
  7. -2
Output示例
  1. 20
    直接爆力+剪枝就过了,普通最大字段和不行,不过可以从前面的非0出发,因为有长度限制。
  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<cmath>
  5. #include<cstring>
  6. using namespace std;
  7.  
  8. typedef long long LL;
  9. const int NN=;
  10.  
  11. int n;
  12. int a[NN*];
  13.  
  14. int main()
  15. {
  16. scanf("%d",&n);
  17. for (int i=;i<=n;i++)
  18. {
  19. scanf("%d",&a[i]);
  20. a[i+n]=a[i];
  21. }
  22. LL ans=,x;
  23. for (int i=;i<=n;i++)
  24. {
  25. x=;
  26. for (int j=i;j<i+n;j++)
  27. {
  28. if (x+a[j]<) break;
  29. else x+=a[j];
  30. ans=max(x,ans);
  31. }
  32. }
  33. printf("%lld\n",ans);
  34. }
1062 序列中最大的数
题目来源: Ural 1079
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题
 收藏
 关注
有这样一个序列a:
a[0] = 0
a[1] = 1
a[2i] = a[i]
a[2i+1] = a[i] + a[i+1]
 
输入一个数N,求a[0] - a[n]中最大的数。
a[0] = 0, a[1] = 1, a[2] = 1, a[3] = 2, a[4] = 1, a[5] = 3, a[6] = 2, a[7] = 3, a[8] = 1, a[9] = 4, a[10] = 3。
例如:n = 5,最大值是3,n = 10,最大值是4。
 
Input
  1. 1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10)
  2. 2 - T + 1行:T个数,表示需要计算的n。(1 <= n <= 10^5)
Output
  1. T行,每行1个最大值。
Input示例
  1. 2
  2. 5
  3. 10
Output示例
  1. 3
  2. 4
    预处理+输出
  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<cmath>
  4. #include<iostream>
  5. #include<cstring>
  6. using namespace std;
  7.  
  8. typedef long long LL;
  9. const int NN=;
  10.  
  11. LL a[NN],ans[NN];
  12.  
  13. int main()
  14. {
  15. a[]=ans[]=;
  16. a[]=ans[]=;
  17. for (int i=;i<NN;i++)
  18. {
  19. if (i%==) a[i]=a[i/];
  20. else a[i]=a[i/]+a[i/+];
  21. ans[i]=max(ans[i-],a[i]);
  22. }
  23. int T,x;
  24. scanf("%d",&T);
  25. while (T--)
  26. {
  27. scanf("%d",&x);
  28. printf("%lld\n",ans[x]);
  29. }
  30. }
1067 Bash游戏 V2
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题
 收藏
 关注
有一堆石子共有N个。A B两个人轮流拿,A先拿。每次只能拿1,3,4颗,拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N,问最后谁能赢得比赛。
例如N = 2。A只能拿1颗,所以B可以拿到最后1颗石子。
 
Input
  1. 1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
  2. 2 - T + 1行:每行1个数N。(1 <= N <= 10^9)
Output
  1. T行,如果A获胜输出A,如果B获胜输出B
Input示例
  1. 3
  2. 2
  3. 3
  4. 4
Output示例
  1. B
  2. A
  3. A
    发现一个循环的规律吧,然后%一下,输出就可以了
  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cmath>
  4. #include<algorithm>
  5. #include<cstring>
  6. using namespace std;
  7.  
  8. const int ans[]={,,,,,,,};
  9.  
  10. int main()
  11. {
  12. int T,x;
  13. scanf("%d",&T);
  14. while (T--)
  15. {
  16. scanf("%d",&x);
  17. x=x%;
  18. if (x==) x=;
  19. printf("%c\n",ans[x]+'A');
  20. }
  21. }
1092 回文字符串
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题
 收藏
 关注
回文串是指aba、abba、cccbccc、aaaa这种左右对称的字符串。每个字符串都可以通过向中间添加一些字符,使之变为回文字符串。
例如:abbc 添加2个字符可以变为 acbbca,也可以添加3个变为 abbcbba。方案1只需要添加2个字符,是所有方案中添加字符数量最少的。
 
Input
  1. 输入一个字符串StrStr的长度 <= 1000
Output
  1. 输出最少添加多少个字符可以使之变为回文字串。
Input示例
  1. abbc
Output示例
  1. 2
    水题,正和反求一次lcs就差不多了。
  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<cmath>
  4. #include<cstring>
  5. #include<iostream>
  6. using namespace std;
  7.  
  8. const int NN=;
  9. char a[NN],b[NN];
  10. int dp[NN][NN];
  11. int main()
  12. {
  13. char temp;
  14. int n,i,j;
  15. scanf("%s",a);
  16. n=strlen(a);
  17. i=;j=n-;
  18. while(i<n) b[i++]=a[j--];
  19. for(i=;i<=n;i++)
  20. for(j=;j<=n;j++)
  21. if(a[i-]==b[j-]) dp[i][j]=max(dp[i-][j-]+,max(dp[i-][j],dp[i][j-]));
  22. else dp[i][j]=max(dp[i-][j-],max(dp[i-][j],dp[i][j-]));
  23. int ans=n-dp[n][n];
  24. printf("%d\n",ans);
  25. }

1042 数字0-9的数量 1050 循环数组最大子段和 1062 序列中最大的数 1067 Bash游戏 V2 1092 回文字符串的更多相关文章

  1. 51nod 1050 循环数组最大子段和【环形DP/最大子段和/正难则反】

    1050 循环数组最大子段和 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 N个整数组成的循环序列a[1],a[2],a[3],…,a[n],求该 ...

  2. 51nod 1050 循环数组最大子段和

    题目链接:51nod 1050 循环数组最大子段和 #include<stdio.h> #include<algorithm> using namespace std; ; l ...

  3. 51nod 1050 循环数组最大子段和【动态规划】

    N个整数组成的循环序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+a[i+1]+-+a[j]的连续的子段和的最大值(循环序列是指n个数围成一个圈,因此需要考虑a[n-1],a[n] ...

  4. 51Nod 1050 循环数组最大子段和 | DP

    Input示例 6 -2 11 -4 13 -5 -2 Output示例 20 分析: 有两种可能,第一种为正常从[1 - n]序列中的最大子字段和:第二种为数组的total_sum - ([1-n] ...

  5. 51nod 1050 循环数组最大子段和 (dp)

    http://www.51nod.com/onlineJudge/questionCode.html#problemId=1050&noticeId=13385 参考:http://blog. ...

  6. 51nod 1050 循环数组最大子段和 单调队列优化DP

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1050 这个呢,这个题之前 求一遍最大值  然后求一遍最小值 ...

  7. 51nod 循环数组最大子段和(动态规划)

    循环数组最大子段和 输入 第1行:整数序列的长度N(2 <= N <= 50000) 第2 - N+1行:N个整数 (-10^9 <= S[i] <= 10^9) 输出   输 ...

  8. [51NOD1959]循环数组最大子段和(dp,思路)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1050 这道题的最大子段和有两种可能,一种是常规的子段和,另一种 ...

  9. 51nod 循环数组最大子段和

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1050 对于普通的数组,只要求一次最大子段和即可.但是这题是可以循环的,所 ...

随机推荐

  1. chrome开发工具指南(五)

    Main Menu Click More  to open the Main Menu. Settings To open Settings, do one of the following: Pre ...

  2. yum安装mariadb-galera同步

    节点             ip地址      hostname                            系统版本   程序版本 node1 10.4.90.90 mysql1 db1 ...

  3. poj 1330 LCA最近公共祖先

    今天学LCA,先照一个模板学习代码,给一个离线算法,主要方法是并查集加上递归思想. 再搞,第一个离线算法是比较常用了,基本离线都用这种方法了,复杂度O(n+q).通过递归思想和并查集来寻找最近公共祖先 ...

  4. Oracle数据库中直方图对执行计划的影响

    在Oracle数据库中,CBO会默认目标列的数据在其最小值low_value和最大值high_value之间均匀分布,并按照均匀分布原则,来计算目标列 施加查询条件后的可选择率以及结果集的cardin ...

  5. 结对编程1.四则运算GUI版

    201421123022 王若凡        201421123026  欧阳勇 coding详细代码 a.需求分析: 这个程序做成GUI(可以是Windows PC 上的,也可以是Mac.Linu ...

  6. IT之光

    作为一个IT界的新新人才,现在拥有第一个博客,可以在这里学习和分享IT方面的知识和技术.

  7. 201521123075 《Java程序设计》第5周学习总结

    1. 本周学习总结 2. 书面作业 作业参考文件下载 1 .代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过?哪句会出现错误?试改正该错误.并分 ...

  8. 201521123009《Java程序设计》第3周学习总结

    1. 本周学习总结 2. 书面作业 代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; pub ...

  9. 201521123087 《Java程序设计》第3周学习总结

    1.本周学习总结 2. 书面作业 代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; publ ...

  10. java程序设计 彩票购买抽奖程序 团队博客

    一.项目介绍 题目要求 功能要求: 模拟福利彩票36选7,实现彩票的抽奖与中奖通知功能. 1.允许注册用户,用户信息包括用户id,用户名,密码,账户金额,电话号码等属性. 2.允许注册用户购买彩票:手 ...