当前位置:网站首页>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
边栏推荐
- Smart world 2030
- [apprendre la programmation FPGA - 49 à partir de zéro]: vision - Comment la puce a - t - elle été conçue?
- When you complain about the roll, others have quietly begun to prepare for the golden three silver four
- MySQL details - aggregation and grouping
- 跨境资讯站
- 想请教一下,如何选择券商?现在网上开户安全么?
- 基于 FPGA 的 RISC CPU 设计(4)关于项目的 36 个问题及其答案
- P7 Erkai early know - registration and application creation
- How does flush open an account? Is it safe to open an account online now?
- Introduction to super dongle scheme
猜你喜欢

Server antivirus

如何成为一名高级数字 IC 设计工程师(4-5)脚本篇:Shell 脚本实现的文件比较操作

C language course design - food warehouse management system

如何成为一名高级数字 IC 设计工程师(4-2)脚本篇:Verilog HDL 代码实现的文件读写操作

Interviewer: with the for loop, why do you need foreach??
Scala 基础 (三):运算符和流程控制

Test a CSDN free download software

How to encrypt anti copy program
![[机缘参悟-33]:眼见不一定为实,大多数时候“眼见为虚”](/img/60/703a5bc3038d28bcf812415032f240.jpg)
[机缘参悟-33]:眼见不一定为实,大多数时候“眼见为虚”

直播预告|SQL也能玩转工业级机器学习?MLOps meetup V3带你一探究竟!
随机推荐
C language course design - food warehouse management system
Necessary technologies for chip manufacturers (1) Introduction
Adding, deleting, checking and modifying stack - dynamic memory
How to use PN junction to measure temperature?
Which is the best billing method for okcc call center
芯片原厂必学技术(1)引言
How to become a senior digital IC Design Engineer (6-7) digital IC Verification: debug skills
okcc呼叫中心的计费方式哪个最好
I have summarized some experiences from the whole process of R & D platform splitting
Zhongyi technology resumed the review status of the gem IPO, and xuxiaofei no longer acted as a practicing lawyer
OculusRiftS与Unity.UI的交互(1)-总览
独家分析 | 软件测试关于简历和面试的真实情况
How does flush open an account? Is it safe to open an account online now?
Qt基础教程:数据类型与容器
Secondary encapsulation of storage (sessionstorage/localstorage) using TS
How to become a senior digital IC Design Engineer (6-5) digital IC Verification: coverage collection
Query any field of any table in JPA to the util method of entity class dto
Use kubernetes resource lock to complete your own ha application
【学习笔记】子集和问题
Understand flex layout in an article