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

输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。

Output

对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。
你可以认为32位整数足以保存结果。

Sample Input

1 3
2 5

Sample Output

4 28
20 152
题目中有一个小陷阱,输入的数m不一定小于n,所以要先判断。
#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
有点坑,必须用double,float不过

#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

输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。

Input

输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。

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

输入数据有多组,每组占一行,包含一个正整数n(1<n<30),表示只剩下一个桃子的时候是在第n天发生的。

Output

对于每组输入数据,输出第一天开始吃的时候桃子的总数,每个测试实例占一行。

Sample Input

2
4

Sample Output

4
22
简单模拟,当第n天时只剩一个桃子,那么第n-1天剩(1+1)*2,第n-2天剩((1+1)*1+1)*2,以此类推...用循环即可求出原先桃子数,用递归也行但循环更快更省内存。
#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

输入数据有多组,每组占一行,包括两个整数m和n(100<=m<=n<=999)。

Output

对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开;
如果给定的范围内不存在水仙花数,则输出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

Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs.

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

The input will consist of a series of pairs of integers i and j, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0.

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

For each pair of input integers i and j you should output i, j, and the maximum cycle length for integers between and including i and j. These three numbers should be separated by at least one space with all three numbers on one line and with one line of output for each line of input. The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line). 

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

Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the state of Louisiana is actually shrinking by 50 square miles each year, due to erosion caused by the Mississippi River. Since Fred is hoping to live in this house the rest of his life, he needs to know if his land is going to be lost to erosion.

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

The first line of input will be a positive integer indicating how many data sets will be included (N).

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

For each data set, a single line of output should appear. This line should take the form of:

“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.
可以使用向上取整函数 ceil()
#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

Many classmates said to me that A+B is must needs.
If you can’t AC this problem, you would invite me for night meal. ^_^

Input

Input may contain multiple test cases. Each case contains A and B in one line.
A, B are hexadecimal number.
Input terminates by EOF.

Output

Output A+B in decimal number in one line.

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 解题相关推荐

  1. 【JAVA】力扣第197场周赛代码+解题思路

    目录 5460. 好数对的数目 解题锦囊 思路一:常规(未用解题锦囊) 代码 思路二:使用解题锦囊 5461. 仅含 1 的子串数 解题锦囊 代码 错误点 5211. 概率最大的路径 解题锦囊 代码 ...

  2. 【JAVA】力扣第198场周赛代码+解题思路——【排名第 1 ~ 300 名的参赛者可获「微软中国」简历内推机会】做对前两道就能排到268/ 5778(4.6%)

    目录 前言 一.题目:5464. 换酒问题 题解 代码 二.题目:5465. 子树中标签相同的节点数 题解 代码 三.题目:5466. 最多的不重叠子字符串 题解 代码 四.5467. 找到最接近目标 ...

  3. LeetCode228场周赛解题报告

    LeetCode228场周赛解题报告 生成交替二进制字符串的最少操作数 原题链接 https://leetcode-cn.com/contest/weekly-contest-228/problems ...

  4. LeetCode第45场双周赛-解题报告

    LeetCode第45场双周赛-解题报告 A. 唯一元素的和 原题链接 https://leetcode-cn.com/problems/sum-of-unique-elements/ 解题思路 因为 ...

  5. Leetcode 第133场周赛解题报告

    今天参加了leetcode的周赛,算法比赛,要求速度比较快.有思路就立马启动,不会纠结是否有更好的方法或代码可读性.只要在算法复杂度数量级内,基本上是怎么实现快速就怎么来了. 比赛时先看的第二题,一看 ...

  6. LeetCode第187场周赛(Weekly Contest 187)解题报告

    差点又要掉分了,还好最后几分钟的时候,绝杀 AK.干巴爹!!! 第一题:思路 + 模拟暴力. 第二题:线性扫描. 第三题:双指针(滑动窗口) + 优先队列. 第四题:暴力每一行最小 k 个 + 优先队 ...

  7. LeetCode第176场周赛(Weekly Contest 176)解题报告

    又是一周掉分之旅,我发现,LeetCode周赛的数据好水,所以有的时候,实在没思路,先暴力解决试试(即使分析出时间复杂度会超时),比如第二题和第三题都可以暴力通过,GG思密达. 这周主要使用了数据结构 ...

  8. Python解题 - CSDN周赛第25期 - 水池注水

    本期四道题都是在每日一练出现过多次的老题,而且后两道题的思维难度颇大,尤其最后一题-水池注水,如果没有提前准备过,问哥是万万不可能在两个小时内做出来的.所以,拿到这个名次,问哥心里其实很虚.提交之后发 ...

  9. Python解题 - CSDN周赛第36期

    本期有点难度,系统也没有多少bug,算是最近 N 期周赛里质量较高的一期比赛了. 第一题:查找点在自然区间的坐标 定义:实数轴上的一个区间由左右两个端点,假设区间是左闭右开的,例如区间`[0,1)`. ...

最新文章

  1. python好找工作吗2017-2017学什么编程语言好找工作?
  2. php和python区别-Python与PHP的一些区别
  3. java内存分配与管理
  4. C# Datagridview完整攻略
  5. 解决 FtpClient 类无法导入 .
  6. linux应用之--网络编程
  7. oppo手机计算机,OPPO手机助手
  8. Spring Boot Mybatis简单使用
  9. linux wireless子系统,Linux Wireless子系统初始化
  10. oracle内连接左连接右连接,ORACLE 左连接 右连接 内连接 区别
  11. 软考高级 真题 2016年上半年 信息系统项目管理师 论文
  12. PMSG孕马血清促性腺激素适用的应用方案
  13. Reno与RACK对丢失/重传报文的标记
  14. OEM产品验收测试用例如何编写
  15. Storm学习笔记——安装配置
  16. Spring Cloud启动-4-应用监听器ApplicationListener之BootstrapApplicationListener
  17. 关于函数不定积分的方法总结
  18. 顺序队列模板简单应用算法设计:农夫过河(这个比较难,我自己都觉得难)
  19. Qt-QtCreator中编译运行出现“程序异常结束”crashed
  20. AMS1117稳压模块

热门文章

  1. wgt包更新时会下载但是不会安装
  2. Python+OpenCV图像处理(五)——图像阈值和二值化
  3. dtu无线 服务器端,4G DTU将数据无线方式上传上位机软件。服务器PC端扩展功能
  4. 航天广电广播系统服务器调试,广播系统应该做哪些调试
  5. 第五章 C++与STL入门 例题
  6. excel学习——相对引用、绝对引用、混合引用
  7. antirez:Redis6真的来了
  8. PythonNote017---计算房贷还款
  9. 2022 年博客总结
  10. 用Python写网络爬虫:推荐这本书看看。