当前位置:网站首页>2022.02.15
2022.02.15
2022-06-29 02:07:00 【Walking code】
Brush questions as usual
Problem description
one day ,JOE Finally can't stand the calculation a^b%c This ordinary operation . So he decided to ask you to write a program , Calculation a^b%c.
Tips : if b It's odd ,,a^b=(a^(b/2))^2*a, otherwise a^b=(a^(b/2))^2.Input format
Three nonnegative integers a,b,c;
Output format
An integer ans, Express a^b%c;
The sample input
7 2 5
Sample output
4
Data size and engagement
30% a <= 100, b <= 10^4, 1 <= c <= 100
60% a <=10^4, b <= 10^5, 1 <= c <= 10^4
100% a <=10^6, b <= 10^9, 1 <= c <= 10^6
This problem involves fast exponentiation , In order to reduce the amount of calculation , The base number needs to be modeled constantly ; At the same time, we should also judge the parity of the index
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,c;
cin>>a>>b>>c;
long long sum=1;
while(b)
{
if(b%2==0)
a=(a*a)%c;
else if(b%2!=0)
{
sum=(a*sum)%c;
a=(a*a)%c;
}
b=b/2;
}
cout<<sum%c;
return 0;
}
Error summary : The first time I want to write a function , The fact proved that , Don't write recursion when you have nothing to do , Otherwise the computer will burn
The second time it exploded , Facts have proved that long long why int
Problem description
Enter any 10 A floating point number , According to their degree of aggregation, they are divided into 3 Group , Output the average value of each group .
Provide a train of thought for teachers to talk in class : take 10 Number to sort on the number axis , Then calculate the distance between every two points , Disconnect at the two largest distances of all distances , This way 10 The numbers are divided into 3 Group .
This question is difficult , If the in-depth discussion is complicated , You can only consider the very simple case of grouping as shown in the following example , As long as the simple case can be calculated successfully , You can score on this question .
in addition , This topic is a little ahead of schedule , It is recommended that you learn about one-dimensional arrays in the first section of the chapter on arrays by yourself , Then use a one-dimensional array to do . Sorting algorithm can refer to trustie Bubble sorting method reference uploaded by the platform .Input format
Ten floating-point numbers to be input , Use spaces to separate
Output format
The average of the three groups , A new line is required for each output
The sample input
An example of input that meets the requirements of the topic .
example 1:
50.4 51.3 52.3 9.5 10.4 11.6 19.1 20.8 21.9 49.6
example 2:
8.6 7.4 3.5 17.9 19.1 18.5 37.6 40.4 38.5 40.0Sample output
The output corresponding to the sample input above .
example 1:
10.5
20.6
50.9
example 2:
6.5
18.5
39.125
Jicao
#include<bits/stdc++.h>
using namespace std;
int main()
{
double a[10];
int i;
for(i=0;i<10;i++)
cin>>a[i];
sort(a,a+10);
double b[10],max1=0,max2=0,sum=0;
for(i=0;i<9;i++)
b[i]=fabs(a[i]-a[i+1]);
int x1,x2,temp;
x1=x2=0;
for(i=0;i<9;i++)
{
if(max2<b[i]&&max1>b[i])
{
max2=b[i];
x2=i;
}
if(max1<b[i])
{
max2=max1;
x2=x1;
max1=b[i];
x1=i;
}
}
if(x1>x2)
{
temp=x1;
x1=x2;
x2=temp;
} //x2>x1
for(i=0;i<=x1;i++)
sum+=a[i];
cout<<sum/(x1+1)<<endl;
sum=0;
for(i=x1+1;i<=x2;i++)
sum+=a[i];
cout<<sum/(x2-x1)<<endl;
sum=0;
for(i=x2+1;i<10;i++)
sum+=a[i];
cout<<sum/(9-x2);
return 0;
}
The main points of : Judge the partition interval
边栏推荐
- PHP hospital network reservation management system source code, hospital consultation reservation registration OA system (commercial or graduation design)
- How to choose source code encryption software
- How does flush open an account? Is it safe to open an account online?
- Is the ETF fund reliable and safe
- Qt基础教程:数据类型与容器
- AHA C language, C language programming introductory books and PPT (PDF version) download website
- 什么叫股票线上开户?网上开户安全么?
- TiFlash 面向编译器的自动向量化加速
- 想请教一下,如何选择券商?现在网上开户安全么?
- 想请教一下,我在中山,到哪里开户比较好?在线开户是安全么?
猜你喜欢
![[redis] hash type](/img/8b/2585908318f5fe88b455323d3f392e.png)
[redis] hash type
![[high concurrency, high performance and high availability of massive data MySQL practice-10] - Implementation of mvcc in InnoDB](/img/dc/a30ccd9943e668aef8c874980a4975.jpg)
[high concurrency, high performance and high availability of massive data MySQL practice-10] - Implementation of mvcc in InnoDB

SAP ui5 beginner tutorial Part 23 - sorting sort and grouping Group trial version of list control

Callback function of unity after importing resources

TiFlash 面向编译器的自动向量化加速
![[redis] data introduction & General Command & string type](/img/86/3abc5047f9c0a051f432e82ccc816c.png)
[redis] data introduction & General Command & string type

如何成为一名高级数字 IC 设计工程师(4-3)脚本篇:C 语言实现的文件读写操作

Dialogue with opensea co creation Alex: we still only touch the tip of the iceberg of NFT capability | chain catcher

I have summarized some experiences from the whole process of R & D platform splitting

基于 RISC-V SoC 的可配置 FFT 系统设计(1)引言
随机推荐
[从零开始学习FPGA编程-49]:视野篇 - 芯片是如何被设计出来的?
如何成为一名高级数字 IC 设计工程师(6-5)数字 IC 验证篇:覆盖率收集
[从零开始学习FPGA编程-50]:视野篇 - 芯片是如何被制造出来的?芯片制造的十三大步骤。
HBuilder左侧工具栏不见了
为什么要在网站上安装SSL证书?
11-Go基础:接口
[redis] hash type
Introduction to super dongle scheme
Redis data migration (III)
Understand flex layout in an article
[redis] sortedset type
Google Borg paper
如何成为一名高级数字 IC 设计工程师(4-5)脚本篇:Shell 脚本实现的文件比较操作
I'd like to ask you, where can I open an account in Zhongshan? Is it safe to open an account online?
Written examination questions, answers and analysis of Digital IC design and FPGA design (2) 2021 Huawei Hisilicon (Part 1)
Crawler exercise (IV) -- IP address problem
SAP ui5 beginner tutorial 24 - how to use OData data model
[redis] data introduction & General Command & string type
okcc呼叫中心的计费方式哪个最好
The metadata request parsing principle of OData XML format applied by SAP ui5 is based on domparser