oi代码模版(包括宏定义和常用代码)

  1 // This file is part of the GNU ISO C++ Library.  This library is free
  2 
  3 // software; you can redistribute it and/or modify it under the
  4 
  5 // terms of the GNU General Public License as published by the
  6 
  7 // Free Software Foundation; either version 3, or (at your option)
  8 
  9 // any later version.
 10 
 11  
 12 
 13 // This library is distributed in the hope that it will be useful,
 14 
 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 
 17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 
 19 // GNU General Public License for more details.
 20 
 21  
 22 
 23 // Under Section 7 of GPL version 3, you are granted additional
 24 
 25 // permissions described in the GCC Runtime Library Exception, version
 26 
 27 // 3.1, as published by the Free Software Foundation.
 28 
 29  
 30 
 31 // You should have received a copy of the GNU General Public License and
 32 
 33 // a copy of the GCC Runtime Library Exception along with this program;
 34 
 35 // see the files COPYING3 and COPYING.RUNTIME respectively.
 36 
 37 #include<fstream>
 38 
 39 #include<iomanip>
 40 
 41 #include<iostream>
 42 
 43 #include<sstream>
 44 
 45 #include<ctime>
 46 
 47 //ios
 48 
 49 #include<algorithm>
 50 
 51 #include<deque>
 52 
 53 #include<functional>
 54 
 55 #include<queue>
 56 
 57 #include<stack>
 58 
 59 #include<map>
 60 
 61 #include<set>
 62 
 63 #include<vector>
 64 
 65 #include<system_error>
 66 
 67 #include<iterator>
 68 
 69 #include<memory>
 70 
 71 //algorithm
 72 
 73 using namespace std;
 74 
 75 namespace fast
 76 
 77 {
 78 
 79     template<class T>
 80 
 81     inline T read(T t)
 82 
 83     {
 84 
 85         T x = 0,sign=1; int c=getchar();
 86 
 87         while (c<48||c>57)
 88 
 89         {
 90 
 91             if(c=='-') sign=-1; c=getchar();
 92 
 93         }
 94 
 95         while (c>=48&&c<=57) x=(x<<3)+(x<<1)+(c^48),c=getchar();
 96 
 97         return x*sign;
 98 
 99     }
100 
101  
102 
103     template<class T>
104 
105     inline void write(T x)
106 
107     {
108 
109         int s=0; char arr[128]; if(x<0) putchar('-'),x=-x;
110 
111         while(x) arr[s++]=x%10^48,x=x/10; if(s==false) arr[s++] = 48;
112 
113         while(s--) putchar(arr[s]);
114 
115     }
116 
117     template<class T>
118 
119     inline void writeln(T x)
120 
121     {
122 
123         write(x); putchar(10);
124 
125     }
126 
127 }
128 
129 class BigInter
130 
131 {
132 
133 friend istream& operator>>(istream&,BigInter&);   //重载输入运算符
134 
135 friend ostream& operator<<(ostream&,BigInter&);   //重载输出运算符
136 
137 public:
138 
139     string str;
140 
141     vector<int> temp;
142 
143     BigInter(const string);     //将一个字符串类型的变量转化为大数
144 
145     BigInter operator *(const BigInter &x)
146 
147     {
148 
149         string num1=x.str,num2=this->str;
150 
151         string ans="";
152 
153         unsigned long len1=num1.size(),len2=num2.size(),add=0;
154 
155         vector<long long>tmp(len1+len2-1);
156 
157         for(int i=0;i<len1;++i)
158 
159         {
160 
161             int p1=num1[i]-'0';
162 
163             for(int j=0;j<len2;++j)
164 
165             {
166 
167                 int p2=num2[j]-'0';
168 
169                 tmp[i+j]+=p1*p2;
170 
171             }
172 
173         }
174 
175         for(int i=int(tmp.size())-1;i>=0;--i)
176 
177         {
178 
179             int now=int(tmp[i])+int(add);
180 
181             static_cast<void>(tmp[i]=now%10),add=now/10;
182 
183         }
184 
185         while(add!=0)
186 
187         {
188 
189             int now=add%10;
190 
191             static_cast<void>(add/=10),tmp.insert(tmp.begin(),now);
192 
193         }
194 
195         for(auto a:tmp)ans+=to_string(a);
196 
197         if(ans.size()>0&&ans[0]=='0')
198 
199         {
200 
201             BigInter t("0"); return t;
202 
203         }
204 
205         BigInter t(ans);
206 
207         return t;
208 
209     }
210 
211     BigInter operator -(const BigInter &x) //高精度减法
212 
213     {
214 
215         string str,str1=this->str,str2=x.str;
216 
217         int temp=int(str1.length())-int(str2.length());
218 
219         int data=0;
220 
221         for(long i=str2.length()-1;i>=0;i--)
222 
223         {
224 
225             if(str1[temp+i]<str2[i]+data)
226 
227             {
228 
229                 str=char(str1[temp+i]-str2[i]-data+'0'+10)+str; data=true;
230 
231             }
232 
233             else
234 
235             {
236 
237                 str=char(str1[temp+i]-str2[i]-data+'0')+str; data=false;
238 
239             }
240 
241         }
242 
243         for(int i=temp-1;i>=0;i--)
244 
245         {
246 
247             if(str1[i]-data>='0')
248 
249             {
250 
251                 str=char(str1[i]-data)+str; data=false;
252 
253             }
254 
255             else
256 
257             {
258 
259                 str=char(str1[i]-data+10)+str; data=true;
260 
261             }
262 
263         }
264 
265         str.erase(0,str.find_first_not_of('0'));//去除前导
266 
267         return str;
268 
269     }
270 
271     BigInter operator +(const BigInter &x)//高精度加法
272 
273     {
274 
275         string str1=this->str,str2=x.str;
276 
277         string str;
278 
279         int len1=int(str1.size()),len2=int(str2.size());
280 
281         //前面补0,弄成长度相同
282 
283         if(len1<len2) for(int i=1;i<=len2-len1;i++) str1="0"+str1;
284 
285         else for(int i=1;i<=len1-len2;i++) str2="0"+str2;
286 
287         int data=0,temp;
288 
289         for(int i=len1-1;i>=0;i--)
290 
291         {
292 
293             temp=str1[i]-'0'+str2[i]-'0'+data;
294 
295             static_cast<void>(data=temp/10),temp%=10;
296 
297             str=char(temp+'0')+str;
298 
299         }
300 
301         if(data!=0) str=char(data+'0')+str;
302 
303         return str;
304 
305     }
306 
307 };
308 
309 istream& operator>>(istream &_istream ,BigInter obj)
310 
311 {
312 
313     _istream>>obj.str;
314 
315     return _istream;
316 
317 }
318 
319 ostream& operator<<(ostream &_ostream ,BigInter obj)
320 
321 {
322 
323     _ostream<<obj.str;
324 
325     return _ostream;
326 
327 }
328 
329 BigInter::BigInter(const string my_number)
330 
331 {
332 
333     str=my_number;
334 
335     for(int i=0;i<my_number.size();i++) temp.push_back(str[i]-'0');
336 
337 }
338 
339 string intToA(int number,int radix) //number是待转数字,radix是指定的进制
340 
341 {
342 
343     string ans="";
344 
345     do
346 
347     {
348 
349         ans=ans+char(number%radix+'0');
350 
351         number=number/radix;
352 
353     }
354 
355     while(number!=0);
356 
357     reverse(ans.begin(),ans.end());
358 
359     return ans;
360 
361 }
362 
363 long long Atoint(string str,int radix) //str是给定的radix进制字符串
364 
365 {
366 
367     long long ans=0;
368 
369     for(int i=0;i<str.size();i++) ans=ans*radix+char(str[i]-'0');
370 
371     return ans;
372 
373 }
374 
375  
376 
377 #define range(start, end, step) for(int i=start;i!=end;i=i+step)
378 
379 #define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
380 
381 #define max(X,Y) ((X)<(Y)?(Y):(X))
382 
383 #define min(Y,X) ((X)<(Y)?(X):(Y))
384 
385 #define debug(a) cout<<a<<endl
386 
387  
388 
389  
390 
391 //░░░░░▄▀▀▀▄░░░░░░░░░░░░░░░░░░
392 
393 //▄███▀░◐░░░▌░░░░░░░░░░░░░░░░░
394 
395 //░░░░▌░░░░░▐░░░░░░░░░░░░░░░░░
396 
397 //░░░░▐░░░░░▐░░░░░░░░░░░░░░░░░
398 
399 //░░░░▌░░░░░▐▄▄░░░░░░░░░░░░░░░
400 
401 //░░░░▌░░░░▄▀▒▒▀▀▀▀▄░░░░░░░░░░
402 
403 //░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄░░░░░░░░
404 
405 //░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄░░░░░░
406 
407 //░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄░░░░
408 
409 //░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄░░
410 
411 //░░░░░░░░░░░▌▌░▌▌░░░░░░░░░░░░
412 
413 //░░░░░░░░░░░▌▌░▌▌░░░░░░░░░░░░
414 
415 //░░░░░░░░░▄▄▌▌▄▌▌░░░░░░░░░░░░
416 
417  
418 
419 //      ┏┛ ┻━━━━━┛ ┻┓
420 
421 //      ┃       ┃
422 
423 //      ┃   ━   ┃
424 
425 //      ┃ ┳┛   ┗┳ ┃
426 
427 //      ┃       ┃
428 
429 //      ┃   ┻   ┃
430 
431 //      ┃       ┃
432 
433 //      ┗━┓   ┏━━━┛
434 
435 //        ┃   ┃   神兽保佑
436 
437 //        ┃   ┃   代码无BUG!
438 
439 //        ┃   ┗━━━━━━━━━┓
440 
441 //        ┃           ┣┓
442 
443 //        ┃             ┏┛
444 
445 //        ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛
446 
447 //          ┃ ┫ ┫   ┃ ┫ ┫
448 
449 //          ┗━┻━┛   ┗━┻━┛
450 
451 //
452 
453 using namespace fast;
454 
455 int main(int argc, const char * argv[])
456 
457 {
458 
459     
460 
461     return 0;
462 
463 }
464 
465  
//谢谢大家
posted @ 2020-10-04 11:39  蒟蒻?蒟蒻!  阅读(293)  评论(0)    收藏  举报