综上,将INF(最大值)设置为0x3f3f3f3f是一个不错的选择!
const int inf=0x3f3f3f3f -- 声明 inf 是 const int型 , const 表示 inf 一旦有了值以后就不允许(通过赋值 来)改变它的值。没有其他意思,就是定义一个“只读”的整型变量 inf,它的值是十六进制的3f3f3f3f。仅此而已。用来代表无穷大
比较精巧的一个INF无穷大值是0x3f3f3f3f。 0x3f3f3f3f的十进制是1061109567,也就是10^9级别的(和0x7fffffff一个数量级),而一般场合下的数据都是小于10^9的。 当我们把无穷大加上一个数据时,它并不会溢出(这就满足了“无穷大加一个有穷的数依然是无穷大”),事实上0x3f3f3f3f+0x3f3f3f3f=21222191...
using namespace std; #include<bits/stdc++.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #define LL long long #define INF 0x3f3f3f3f map<string,int>mp; string s; map <string,int> ::iterator iter; void acc_ios() { ios::sync_with_stdio(...
#include<bits/stdc++.h>usingnamespacestd; typedeflonglongll; typedef pair<int,int>pii;constintN = 1e3+10,inf =0x3f3f3f3f;intmain() { pii p; p= {1,2}; cout<< p.first <<""<
constllinf=0x3f3f3f3f; constintmx=0; voidprint(__int128x) { if(!x) { puts("0"); return; } stringret=""; while(x) { ret+=x%10+'0'; x/=10; } reverse(ret.begin(),ret.end()); cout<<ret<<endl; } intmain(){ ...
const int inf = 0x3f3f3f3f; int n, m; vector<pair<int, int>> g[maxn]; __gnu_pbds::priority_queue<pair<int, int>, greater<>> heap; __gnu_pbds::priority_queue<pair<int, int>, greater<>>::point_iterator p[maxn]; // dis[i] and iterator for decrease-key ...
const int INF = 0x3f3f3f3f; const db eps = 1e-8; const int maxn = 1e5 + 5; const int mod = 2012; const int maxs = 12; In ll read() { ll ans = 0; char ch = getchar(), las = ' '; while(!isdigit(ch)) las = ch, ch = getchar(); ...
const int inf=0x3f3f3f3f; int main(){ int k,p; cin>>k>>p; long long x; long long ans=0; string a; for(int i=1;i<=k;i++){ stringstream ss; ss<<i; a=ss.str(); string b(a.rbegin(),a.rend()); //这里为声明b为a的逆序 a=a+b; x=atoll(a.c_str()); x%=p;...
为避免此类问题,精巧地选择INF值为0x3f3f3f3f。在C/C++中,INT_MAX和INT_MIN分别定义最大和最小整数,位于limits.h头文件内。具体数值上,int类型占4字节32位,故INT_MAX = 2^31-1,INT_MIN = -2^31。超过此范围的整数会导致溢出,引发警告但不出现错误。若需表示更大整数,可使用long ...