当前位置:网站首页>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;
}
边栏推荐
- C language - minesweeping
- 渗透测试-提权专题
- Laravel Aurora push
- 投资理财产品的年限要如何选?
- Visual studio 2022 interface beautification tutorial
- Route parameters to jump to the page and transfer parameters -- > hidden parameter list
- CopyPlugin Invalid Options options should be array ValidationError: CopyPlugin Invalid Options
- Working principle of asemi three-phase rectifier bridge
- How to add an external header file in vs?
- JS handwriting depth clone array and object
猜你喜欢

Detailed summary of flex layout

Specific operations for uploading pictures in PHP

Dynamic programming example 2 leetcode62 unique paths

How to download and use Xiaobai one click reload on the official website
![[Huawei machine test] hj16 shopping list](/img/54/d28f5aea9350af7797ca7c069e564d.jpg)
[Huawei machine test] hj16 shopping list

渗透测试-提权专题

Use js to simply implement the apply, call and bind methods

Activereportsjs V3.0 comes on stage

Working principle of asemi three-phase rectifier bridge

Eyeshot Ultimate 2022 Crack By Xacker
随机推荐
Critical dependency: require function is used in a way in which dependencies
Detailed summary of float
A summary of the experiment of continue and break in C language
Create dynamic array
[pan Wai 1] Huawei computer test
Understand JS high-order function and write a high-order function
CTFHUB SSRF
Rce code execution & command execution (V)
Deeply understand the characteristics of standard flow and off standard elements
parallel recovery slave next change & parallel recovery push change
cuda编译报错
Duplicate symbols for architecture i386 clang
Array: force deduction dichotomy
JSON Library Tutorial from scratch (II): parsing digital learning and sorting notes
Implementation of websocket long connection by workman under laravel
Page electronic clock (use js to dynamically obtain time display)
First blog
Extend the toolbar of quill editor
Professional things use professional people
Go deep into the working principle of browser and JS engine (V8 engine as an example)