HDOJ1001-1005题解
1001--Sum Problem(http://acm.hdu.edu.cn/showproblem.php?pid=1001)
#include <stdio.h> int sum(int n)
{
if(n % )
return (n + ) / * n;
else
return (n / ) * (n + );
} int main()
{
int n;
while(scanf("%d",&n) != EOF){
printf("%d\n\n",sum(n));
}
return ;
}
1002--A + B Problem II(http://acm.hdu.edu.cn/showproblem.php?pid=1002)
注意格式(Case的首字母大写、各种空格、每一行之间有空行,最后一行没有空行)!
给出几组测试数据:
6
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void solve()
{
int n,i,j,k,flag,t,cas,L;
char a[],b[],c[];
scanf("%d",&n);
getchar();
cas=;
while(n--)
{
flag=;
memset(a,'\0',sizeof(a));
memset(b,'\0',sizeof(b));
memset(c,'\0',sizeof(c));
scanf("%s",a);
scanf("%s",b);
printf("Case %d:\n",cas);
printf("%s",a);
printf(" + ");
printf("%s",b);
printf(" = ");
strrev(a);
strrev(b);
k=i=;
L=(strlen(a)>strlen(b)?strlen(b):strlen(a));
while(i<L)
{
t=(a[i]-'')+(b[i]-'')+flag;
flag=(t>=?:);
c[k++]=t%+'';
i++;
}
if(a[i]=='\0')
{
while(b[i]!='\0') {
t=b[i++]-''+flag;
c[k++]=t%+'';
flag=(t>=?:);
}
}
else
{
while(a[i]!='\0') {
t=a[i++]-''+flag;
c[k++]=t%+'';
flag=(t>=?:);
}
}
if(flag) c[k]='';
else k--;
while(k>=)
{
printf("%c",c[k]);
k--;
}
printf("\n");
if(n>) printf("\n");
cas++;
}
} int main()
{
solve();
return ;
}
1003--Max Sum(http://acm.hdu.edu.cn/showproblem.php?pid=1003)
#include<iostream>
#include<cstdio>
using namespace std; void solve()
{
int T, i, max,sum,n,num,begin,end,t,con;
while(cin>>T) {
for(i = ; i <= T; i++) {
max = -;
sum = ;
n = con = ;
cin>>n;
num = n;
begin = end = ;
while(n--) {
cin>>t;
sum += t;
con++;
if(sum > max) {
begin = con;
max = sum;
end = num - n;
}
if(sum < ) {
sum = ;
con = ;
}
}
cout<<"Case "<<i<<":"<<endl<<max<<" "<<end-begin+<<" "<<end<<endl;
if(i != T) cout<<endl;
}
}
} int main()
{
solve();
return ;
}
1004--Let the Balloon Rise(http://acm.hdu.edu.cn/showproblem.php?pid=1004)
#include<iostream>
#include<cstdio>
#include<map>
#include<string>
#include<cstring>
using namespace std; void solve()
{
int T, max, t;
map<string, int> color_count;
string color;
while(cin>>T && T) {
max = ;
while(T--) {
cin>>color;
++color_count[color];
}
map<string, int>::const_iterator ii, it;
it = color_count.begin();
while(it != color_count.end()) {
if(max < it->second) {
max = it->second;
ii = it;
}
it++;
}
cout<<ii->first<<endl;
color_count.clear();
}
} int main()
{
solve();
return ;
}
1005--Number Sequence(http://acm.hdu.edu.cn/showproblem.php?pid=1005)
#include<iostream>
using namespace std; void solve()
{
int A, B, n;
while(cin>>A>>B>>n && (A || B || n)) {
int a[] = {, };
for(int i = ; i < (n % - ) / ; i++) {
a[] = (A * a[] + B * a[]) % ;
a[] = (A * a[] + B * a[]) % ;
}
if(n % ) {
cout<<a[]<<endl;
} else {
cout<<a[]<<endl;
}
}
} int main()
{
solve();
return ;
}
HDOJ1001-1005题解的更多相关文章
- PAT 乙级 1005
题目 题目地址:PAT 乙级 1005 题解 本题主要就在于将一个数的一系列计算结果不重复地存储起来并便于检索,考虑到STL中的集合有相似的特性,使用set可以有效地简化代码和运算. 过程如下: (初 ...
- Leetcode题解 - 贪心算法部分简单题目代码+思路(860、944、1005、1029、1046、1217、1221)
leetcode真的是一个学习阅读理解的好地方 860. 柠檬水找零 """ 因为用户支付的只会有5.10.20 对于10元的用户必须找一个5 对于20元的用户可以找(三 ...
- 题解西电OJ (Problem 1005 -跳舞毯)--动态规划
Description zyf不小心得了一种怪病,为了维持一天的精力他必须不停跳动.于是他买了一条跳舞毯,每天跳上几小时.众所周知,跳舞毯是给定一个序列,让你在指定时间踏指定的按钮,但zyf似乎不怎么 ...
- PAT甲题题解-1005. Spell It Right (20)-数位求和,水
把每个位上的数字求和sum,然后以英文单词的形式输出sum的每个位 #include <iostream> #include <cstdio> #include <alg ...
- Light OJ 1005 - Rooks 数学题解
版权声明:本文作者靖心.靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...
- 【实(dou)力(bi)首(mai)发(meng)】第四次CCF软件能力认证题解
这次的题总体上相对前三次偏简单.由于实力有限,就分析前四题. 试题编号: 201503-1 试题名称: 图像旋转 时间限制: 5.0s 内存限制: 256.0MB 问题 ...
- Codeforces Round #383 (Div. 2) 题解【ABCDE】
Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- BestCoder Round #60 题解链接
题解 题目 1001 GT and sequence 注意先特判000的情况:如果读入的数据有000,那么去掉所有的000且最后答案和000取一个max. 剩下的正数显然全部乘起来比较优. 对于负数 ...
- 递推DP 赛码 1005 Game
题目传送门 /* 递推DP:官方题解 令Fi,j代表剩下i个人时,若BrotherK的位置是1,那么位置为j的人是否可能获胜 转移的时候可以枚举当前轮指定的数是什么,那么就可以计算出当前位置j的人在剩 ...
随机推荐
- php版本历史
php最初就是为了快速构建一个web页面而迅速被大家广为接受的.它的好处是在代码中能内嵌html的代码,从而让程序员能再一个页面中同时写html代码和php代码就能生成一个web页面. 这篇文章用时间 ...
- 【原创】Kakfa utils源代码分析(三)
Kafka utils包最后一篇~~~ 十五.ShutdownableThread.scala 可关闭的线程抽象类! 继承自Thread同时还接收一个boolean变量isInterruptible表 ...
- 简单横道图Demo
代码(每个月都显示整月): @{ ViewBag.Title = "横道图"; Layout = "~/Views/Shared/_Layout.cshtml" ...
- The SQL Server Service Broker for the current database is not enabled, and as a result query notifications are not supported.
当Insus.NET尝试解决此问题<When using SqlDependency without providing an options value, SqlDependency.Star ...
- 十条jQuery代码片段助力Web开发效率提升
JQuery是继prototype之后又一个优秀的Javascript库.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari 2.0+, Oper ...
- 【C#】在窗体中水平居中的控件,到了XP下不居中的解决办法
我时不时会遭遇这个操蛋问题,今天得闲研究了一下,解决如下: A.将窗体FormBorderStyle属性改为Fixed系,当然这会导致用户不能拖拉窗口大小,所以你可能需要B计划↓ B.确保在[VS]中 ...
- TreeView使用
1.添加节点,实现拖拽功能 private void Form1_Load(object sender, EventArgs e) { TreeNode node1 = new TreeNode(); ...
- 关于JAVA数据储存
关于JAVA数据储存: 在JAVA中,有六个不同的地方可以存储数据: 1. 寄存器(register) 这是最快的存储区,因为它位于不同于其他存储区的地方--处理器内部.但是寄存器的数量极其有限,所以 ...
- 第2章 如何构建布局良好的Windows程序
01.菜单栏(MenuStrip) 设置快捷键方式: 方式一:1.设置菜单项的Text属性为(打开(&F)), 首先必须按住alt+主菜单快捷键进入到对应的主菜单, 然后直接按F就可以打开子窗 ...
- css3加载ing动画
项目中ajax交互成功前总会需要给用户提醒,比如请稍候.正在加载中等等,那个等待的动图以前项目中用的是gif,在移动端画质很渣,有毛边,于是在新项目中用css3展示加载中的动画效果. function ...