当前位置:网站首页>2.20 learning content
2.20 learning content
2022-06-25 05:21:00 【Caramel K】
A collection of bits and pieces of knowledge
One 、 Negative modulo
In mathematics , The remainder of a negative number is a positive number . But in c++ in , Modulus of negative number is negative .
For example, in Mathematics ,-10 Divide 3 Remainder is 2; And in the c++ in ,-10%3=-1.
#include<iostream>
using namespace std;
int main()
{
cout<< -10%3 <<endl;
return 0;
}

Two 、pow Function USES
Use pow Function time , The exponent position must be a floating point number .
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int x1 = 1;
float x2 = 1.0;
double x3 = 1.0;
for(int i=1;i<=10;i++)
cout<<pow(i,x1/2)<<"\t"<<pow(i,x2/2)<<"\t"<<pow(i,x3/2)<<endl;
return 0;
}

besides , I also read some other blogs , For bloggers printf Output directly with %d There will be a loss of accuracy , But there was a mess in my own compiler . So if you want to use printf The output still needs %f or %lf, Or add... Before it (int) It is safer to make a strong transition .
3、 ... and 、 Some recently written questions
1.[NOIP2005] Trees outside the school gate
The main idea of the topic : There is a section of road where a tree is planted every other meter ( Including endpoint ), The title will give you some intervals , Let you remove the trees in these intervals ( Including endpoint ), These intervals may overlap , Ask how many trees are left .
Their thinking : Set this path as an array and initialize it to 0, Let the points in each interval be ++, The final statistic is 0 The number of .
very violence convenient .
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int len,t,l,r;
cin>>len>>t;
int a[len+1];
memset(a,0,sizeof(a));
while(t--)
{
cin>>l>>r;
for(int i=l;i<=r;i++) a[i]++;
}
int sum=0;
for(int i=0;i<=len;i++)
if(a[i]==0) sum++;
cout<<sum<<endl;
return 0;
}
2. A simple big number addition problem
I know it's easy to add big numbers, but because I'm a good cook, I WA Don't laugh at me for asking for big chores many times
General meaning : There are two that are no longer than 5000 Add the numbers of , Both numbers may have leading zeros , Please output its sum , But do not output leading zeros .
Their thinking : Input with a character array , Add bitwise and write in a int Type array , Operate on this array : If it is greater than 10 Then carry . Finally, delete the leading zero .
#include<iostream>
#include<cstring>
using namespace std;
char x[5010],y[5010];
int ans[5010];
int main(){
int t;
cin>>t;
while(t--)
{
cin>>x>>y;
int len1=strlen(x);
int len2=strlen(y);
int i=len1-1,j=len2-1;
int k=0;
while(i>=0 && j>=0) ans[k++]+=x[i--]-'0'+y[j--]-'0';
while(i>=0) ans[k++]+=x[i--]-'0';
while(j>=0) ans[k++]+=y[j--]-'0';
for(i=0;i<=k;i++)
{
if(ans[i]>=10)
{
ans[i+1] += ans[i]/10;// carry
ans[i] = ans[i]%10;
}
}
while(ans[k]==0) k--;
// It is very convenient to delete leading zeros
for(i=k;i>=0;i--)cout<<ans[i];
cout<<endl;
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
memset(ans,0,sizeof(ans));
}
return 0;
}
边栏推荐
猜你喜欢

A review of small sample learning

Enhanced paste quill editor
![H5 native player [learn video]](/img/51/83a200d0423b7274d1e981ec2ede2c.jpg)
H5 native player [learn video]

Laravel's little knowledge

Attack and defense world web baby Web

Everything is an object

Personalized Federated Learning with Moreau Envelopes

Go deep into the working principle of browser and JS engine (V8 engine as an example)

UVA816 Abbott’s Revenge

Detailed summary of flex layout
随机推荐
CopyPlugin Invalid Options options should be array ValidationError: CopyPlugin Invalid Options
Go Context - Cancelation and Propagation
Native JS high risk reminder pop-up code snippet, "are you sure you want to do this?" and "it cannot be recovered after deletion. Do you want to continue“
2021-03-23
Go Concurrency
Penetration information collection steps (simplified version)
Penetration test - right raising topic
Mobile number regular expression input box loses focus verification
Apache+php uploading large files
Critical dependency: require function is used in a way in which dependencies
Precise delay based on Cortex-M3 and M4 (systick delay of system timer can be used for STM32, aducm4050, etc.)
渗透测试-提权专题
Double recursion in deep analysis merge sort
Enhanced paste quill editor
HR took the initiative to raise the salary of the test lady. How did she do it?
TeeChart Pro ActiveX 2022.1
MySQL prevents Chinese garbled code and solves the problem of Chinese garbled code
TX Text Control 30.0 ActiveX
Five simple data types of JS
滲透測試-提權專題