周赛 Newstar 解题
Problem A
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 33 Accepted Submission(s) : 6
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
你可以认为32位整数足以保存结果。
Sample Input
1 3 2 5
Sample Output
4 28 20 152
#include<stdio.h>
#define swap(a,b) {a=a+b; b=a-b; a=a-b;}int main()
{int x,y,i,ans1,ans2;while(scanf("%d %d",&x,&y)!=EOF){ans1=0; ans2=0;if(x>y) swap(x,y);for(i=x;i<=y;i++){if(i%2) ans2+=i*i*i;else ans1+=i*i;}printf("%d %d\n",ans1, ans2);}return 0;
}
Problem B
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 13 Accepted Submission(s) : 5
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
123 -234.00
Sample Output
123.00 234.00
#include<stdio.h>int main()
{double n;while(scanf("%lf",&n)!=EOF){if(n<0) printf("%.2lf\n",-n);else printf("%.2lf\n",n);}return 0;
}
Problem C
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 11 Accepted Submission(s) : 4
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
0 0 0 1 0 1 1 0
Sample Output
1.00 1.41
#include<stdio.h>
#include<math.h>int main()
{double x1,x2,y1,y2,ans;while(scanf("%lf %lf %lf %lf",&x1, &y1, &x2, &y2)!=EOF){ans=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));printf("%.2lf\n",ans);}return 0;
}
Problem D
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 6 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
什么问题?他研究的问题是蟠桃一共有多少个!
不过,到最后,他还是没能解决这个难题,呵呵^-^
当时的情况是这样的:
第一天悟空吃掉桃子总数一半多一个,第二天又将剩下的桃子吃掉一半多一个,以后每天吃掉前一天剩下的一半多一个,到第n天准备吃的时候只剩下一个桃子。聪明的你,请帮悟空算一下,他第一天开始吃的时候桃子一共有多少个呢?
Input
Output
Sample Input
2 4
Sample Output
4 22
#include<stdio.h>int main()
{int n,ans,i;while(scanf("%d",&n)!=EOF){ans=1;for(i=1;i<n;i++){ans=(ans+1)*2;}printf("%d\n",ans);}return 0;
}
Problem E
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 17 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。
现在要求输出所有在m和n范围内的水仙花数。
Input
Output
如果给定的范围内不存在水仙花数,则输出no;
每个测试实例的输出占一行。
Sample Input
100 120 300 380
Sample Output
no 370 371
循环判断
#include<stdio.h>bool is_shui(int x)
{int sum=0,ans=x;while(x!=0){sum+=(x%10)*(x%10)*(x%10);x/=10;}if(ans==sum) return true;else return false;
}int main()
{int m,n,i,j;bool flag;while(scanf("%d%d",&m,&n)!=EOF){flag=false;for(i=m;i<=n;i++){if(is_shui(i) ){if(flag){printf(" ");printf("%d",i);}else{printf("%d",i);flag=true;}}}if(flag) printf("\n");else printf("no\n");}
}
Problem F
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 6 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Consider the following algorithm:
1. input n
2. print n
3. if n = 1 then STOP
4. if n is odd then n <- 3n + 1
5. else n <- n / 2
6. GOTO 2
Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers n such that 0 < n < 1,000,000 (and, in fact, for many more numbers than this.)
Given an input n, it is possible to determine the number of numbers printed (including the 1). For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16.
For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j.
Input
You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j.
You can assume that no opperation overflows a 32-bit integer.
Output
Sample Input
1 10 100 200 201 210 900 1000
Sample Output
1 10 20 100 200 125 201 210 89 900 1000 174
简单模拟,按要求计算程序运行的次数,但是此题也有一个小陷阱,输入的i,j不一定升序,而且在输出时必选按如输入时的顺序输出
#include<stdio.h>
#define swap(a,b) {a=a+b; b=a-b; a=a-b;}int whatstep(int num)
{int ans=1;while(num!=1){if(num%2) num=3*num+1;else num/=2;ans++;}return ans;
}int main()
{int n, m, i, j, max, step;while(scanf("%d %d",&n,&m)!=EOF){max=0;if(n>m){i=m; j=n;}else{i=n; j=m;}for(;i<=j;i++){step=whatstep(i);max=max>step?max:step;}printf("%d %d %d\n",n,m,max);}return 0;
}
Problem G
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 2 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Descriptio
After doing more research, Fred has learned that the land that is being lost forms a semicircle. This semicircle is part of a circle centered at (0,0), with the line that bisects the circle being the X axis. Locations below the X axis are in the water. The semicircle has an area of 0 at the beginning of year 1. (Semicircle illustrated in the Figure.)
Input
Each of the next N lines will contain the X and Y Cartesian coordinates of the land Fred is considering. These will be floating point numbers measured in miles. The Y coordinate will be non-negative. (0,0) will not be given.
Output
“Property N: This property will begin eroding in year Z.”
Where N is the data set (counting from 1), and Z is the first year (start from 1) this property will be within the semicircle AT THE END OF YEAR Z. Z must be an integer.
After the last data set, this should print out “END OF OUTPUT.”
Notes:
1. No property will appear exactly on the semicircle boundary: it will either be inside or outside.
2. This problem will be judged automatically. Your answer must match exactly, including the capitalization, punctuation, and white-space. This includes the periods at the ends of the lines.
3. All locations are given in miles.
Sample Input
2 1.0 1.0 25.0 0.0
Sample Output
Property 1: This property will begin eroding in year 1. Property 2: This property will begin eroding in year 20. END OF OUTPUT.
#include<stdio.h>
#include<math.h>
#define Pi 3.1415926
int main()
{int n,i;scanf("%d",&n);for(i=1;i<=n;i++){double x,y,r,s;int year;scanf("%lf %lf",&x,&y);r=sqrt(x*x+y*y);s=Pi*r*r;year=ceil(s/2/50);printf("Property %d: This property will begin eroding in year %d.\n",i,year);}printf("END OF OUTPUT.\n");return 0;
}
Preblem H 是个大数,改天专门开一帖讲解。
Problem I
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 4 Accepted Submission(s) : 4
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
If you can’t AC this problem, you would invite me for night meal. ^_^
Input
A, B are hexadecimal number.
Input terminates by EOF.
Output
Sample Input
1 9 A B a b
Sample Output
10 21 21
#include<stdio.h>int main()
{int x,y;while(scanf("%x %x",&x, &y)!=EOF){printf("%d\n",x+y);}return 0;
}
周赛 Newstar 解题相关推荐
- 【JAVA】力扣第197场周赛代码+解题思路
目录 5460. 好数对的数目 解题锦囊 思路一:常规(未用解题锦囊) 代码 思路二:使用解题锦囊 5461. 仅含 1 的子串数 解题锦囊 代码 错误点 5211. 概率最大的路径 解题锦囊 代码 ...
- 【JAVA】力扣第198场周赛代码+解题思路——【排名第 1 ~ 300 名的参赛者可获「微软中国」简历内推机会】做对前两道就能排到268/ 5778(4.6%)
目录 前言 一.题目:5464. 换酒问题 题解 代码 二.题目:5465. 子树中标签相同的节点数 题解 代码 三.题目:5466. 最多的不重叠子字符串 题解 代码 四.5467. 找到最接近目标 ...
- LeetCode228场周赛解题报告
LeetCode228场周赛解题报告 生成交替二进制字符串的最少操作数 原题链接 https://leetcode-cn.com/contest/weekly-contest-228/problems ...
- LeetCode第45场双周赛-解题报告
LeetCode第45场双周赛-解题报告 A. 唯一元素的和 原题链接 https://leetcode-cn.com/problems/sum-of-unique-elements/ 解题思路 因为 ...
- Leetcode 第133场周赛解题报告
今天参加了leetcode的周赛,算法比赛,要求速度比较快.有思路就立马启动,不会纠结是否有更好的方法或代码可读性.只要在算法复杂度数量级内,基本上是怎么实现快速就怎么来了. 比赛时先看的第二题,一看 ...
- LeetCode第187场周赛(Weekly Contest 187)解题报告
差点又要掉分了,还好最后几分钟的时候,绝杀 AK.干巴爹!!! 第一题:思路 + 模拟暴力. 第二题:线性扫描. 第三题:双指针(滑动窗口) + 优先队列. 第四题:暴力每一行最小 k 个 + 优先队 ...
- LeetCode第176场周赛(Weekly Contest 176)解题报告
又是一周掉分之旅,我发现,LeetCode周赛的数据好水,所以有的时候,实在没思路,先暴力解决试试(即使分析出时间复杂度会超时),比如第二题和第三题都可以暴力通过,GG思密达. 这周主要使用了数据结构 ...
- Python解题 - CSDN周赛第25期 - 水池注水
本期四道题都是在每日一练出现过多次的老题,而且后两道题的思维难度颇大,尤其最后一题-水池注水,如果没有提前准备过,问哥是万万不可能在两个小时内做出来的.所以,拿到这个名次,问哥心里其实很虚.提交之后发 ...
- Python解题 - CSDN周赛第36期
本期有点难度,系统也没有多少bug,算是最近 N 期周赛里质量较高的一期比赛了. 第一题:查找点在自然区间的坐标 定义:实数轴上的一个区间由左右两个端点,假设区间是左闭右开的,例如区间`[0,1)`. ...
最新文章
- python好找工作吗2017-2017学什么编程语言好找工作?
- php和python区别-Python与PHP的一些区别
- java内存分配与管理
- C# Datagridview完整攻略
- 解决 FtpClient 类无法导入 .
- linux应用之--网络编程
- oppo手机计算机,OPPO手机助手
- Spring Boot Mybatis简单使用
- linux wireless子系统,Linux Wireless子系统初始化
- oracle内连接左连接右连接,ORACLE 左连接 右连接 内连接 区别
- 软考高级 真题 2016年上半年 信息系统项目管理师 论文
- PMSG孕马血清促性腺激素适用的应用方案
- Reno与RACK对丢失/重传报文的标记
- OEM产品验收测试用例如何编写
- Storm学习笔记——安装配置
- Spring Cloud启动-4-应用监听器ApplicationListener之BootstrapApplicationListener
- 关于函数不定积分的方法总结
- 顺序队列模板简单应用算法设计:农夫过河(这个比较难,我自己都觉得难)
- Qt-QtCreator中编译运行出现“程序异常结束”crashed
- AMS1117稳压模块