当前位置:网站首页>Zheng Qing 21 ACM is fun. (3) part of the problem solution and summary
Zheng Qing 21 ACM is fun. (3) part of the problem solution and summary
2022-07-05 05:20:00 【hunziHang】
1. problem C: an isosceles triangle ( Main pit points : Data range )
Problem description :
While wiping the table , One of the volunteers found some tables shaking , Smart volunteers immediately thought of the principle that triangles have stability . To form a triangle , Volunteers found three sticks , The lengths are a,b,c. Now smart, can you tell us that these three sticks can form an isosceles triangle ?
Input :
Multiple sets of test data
Enter three positive integers a、b and c, Each represents three sides of the triangle (a,b,c Both in int Within the scope of ).
Output :
If it is isosceles triangle output "Yes", Otherwise output "No".
The sample input :
1 2 2
Sample output :
Yes
Cause analysis :
1. Although the title said (a,b,c Both in int Within the scope of ), But when finding the sum of two sides , May exceed int Data range , therefore int Change it to long long That's all right. .
2. Only one example is given , You will mistakenly think that there are not multiple instances , But the title says multi instance input , So pay attention to the examination .
Solution :
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long a,b,c;
scanf("%lld%lld%%lld",&a,&b,&c)
if(a+b>c&&a+c>b&&b+c>a)
{
if(a==b||a==c||b=c)
printf("Yes\n");
else
printf("No\n");
}
else
printf("No\n");
}
}
2. problem E: Print graphics
Problem description :
According to the input capital English letters , Print graphics in the following form . for example , Input G
A
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFGInput :
Enter a capital letter
Output :
Output the right triangle described by the topic
The sample input :
E
Sample output :
A AB ABC ABCD ABCDE
Cause analysis :
The main point of this question is How to use the input capital letters to become Numbers , Thus the problem of how many lines to print is solved .
namely utilize n=x-'A'+1; Create an array , keep for the future 26 Letters
Solution :
#include<stdio.h>
int main()
{
int i,j,k,n;
char a[30]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'},x;
scanf("%c",&x);
n=x-'A'+1;
for(i=1;i<=n;i++)
{
for(j=n-i;j>0;j--)
printf(" ");
for(k=0;k<i;k++)
printf("%c",a[k]);
printf("\n");
}
return 0;
}3. problem I: Preparation before the game -- shift
Problem description :
After a long time of labor . The volunteers are exhausted ( I really appreciate them ), But there are still many tasks . So the volunteers came up with a way , Use three numbers to decide who will do the next task , So that others can rest .
The rule is : Three numbers n、m and k, Everyone chooses one 0-9 The number of , according to n/m Of the k Decimals to determine who will come to the next task , If n/m Of the k The number of decimal places is s, So choose s The numbered people rest . Xiao Ming is too tired , So ask how you can get the answer quickly .
Input :
Multiple sets of test data .
Each set of test data input has three positive integers n,m,k.(1<=n, m<=1000, 1<=k<=100000)
Output :
Output n/m Of the k Numbers in decimal places .
The sample input :
1 2 3 1 3 3
Sample output :
0 3
Cause analysis :
High precision problem , Directly according to the mathematical method Simulation is enough
1. int n1=n%m; for instance 10/3 Then it must be the remainder to operate , So first take the remainder .
2. m1=(n1*10)/m; m1 That is, the decimal part because 10/3 more than 1 The next step should be math 10/3 therefore n1*10. also /
3. Update the remainder n1=(n1*10)%m;
Solution :
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n,m,k;
while(scanf("%d%d%d",&n,&m,&k)!=EOF){
int n1=n%m;
int m1=0;
int sum1=0;
while(sum1<k){
m1=(n1*10)/m;
n1=(n1*10)%m;
sum1++;
}
printf("%d\n",m1);
}
return 0;
}
summary :
1. When doing questions Seriously Fast Reading questions , Sift out secondary information .
2.int You can all Defined as long long avoid Out of data range
3. Come on, understand and train characters
边栏推荐
- Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
- Romance of programmers on Valentine's Day
- Optimization scheme of win10 virtual machine cluster
- [allocation problem] 455 Distribute cookies
- Cocos create Jiugongge pictures
- Demonstration of using Solon auth authentication framework (simpler authentication framework)
- Research on the value of background repeat of background tiling
- [interval problem] 435 Non overlapping interval
- Insert sort
- ssh免密登录设置及使用脚本进行ssh登录并执行指令
猜你喜欢

Research on the value of background repeat of background tiling

支持多模多态 GBase 8c数据库持续创新重磅升级

lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8

Double pointer Foundation

《动手学深度学习》学习笔记

To the distance we have been looking for -- film review of "flying house journey"
![[speed pointer] 142 circular linked list II](/img/f8/222a360c01d8ef120b61bdd2025044.jpg)
[speed pointer] 142 circular linked list II

小程序直播+电商,想做新零售电商就用它吧!

Magnifying glass effect
![[turn to] MySQL operation practice (I): Keywords & functions](/img/b1/8b843014f365b786e310718f669043.png)
[turn to] MySQL operation practice (I): Keywords & functions
随机推荐
一个新的微型ORM开源框架
[转]: OSGI规范 深入浅出
To be continued] [UE4 notes] L4 object editing
Haut OJ 1321: mode problem of choice sister
利用HashMap实现简单缓存
Yolov5 adds attention mechanism
Collapse of adjacent vertical outer margins
Service fusing hystrix
Haut OJ 1357: lunch question (I) -- high precision multiplication
2022上半年全国教师资格证下
【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
[转]:Apache Felix Framework配置属性
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
Ue4/ue5 illusory engine, material part (III), material optimization at different distances
Solon Auth 认证框架使用演示(更简单的认证框架)
2022年上半年国家教师资格证考试
GBase数据库助力湾区数字金融发展
Find a good teaching video for Solon framework test (Solon, lightweight application development framework)
Haut OJ 1352: string of choice
win下一键生成当日的时间戳文件