• [NOIP2002 普及组] 产生数


    1. #include
    2. using namespace std;
    3. struct Int
    4. {
    5. #define MAXN 100000
    6. int a[MAXN + 10];
    7. Int()
    8. {
    9. *this = 0;
    10. }
    11. Int(const long long num)
    12. {
    13. *this = num;
    14. }
    15. Int(const string s)
    16. {
    17. *this = s;
    18. }
    19. Int& operator = (string s)
    20. {
    21. bool flag = false;
    22. if(s[0] == '-')
    23. {
    24. flag = true;
    25. s.erase(0,1);
    26. }
    27. a[0] = s.size();
    28. for(int i = 0;i < int(s.size());i++)
    29. {
    30. a[a[0] - i] = s[i] - '0';
    31. }
    32. if(flag)
    33. {
    34. for(int i = 1;i <= a[0];i++)
    35. {
    36. a[i] = -a[i];
    37. }
    38. }
    39. return *this;
    40. }
    41. Int& operator = (const long long num)
    42. {
    43. if(num < 0)
    44. {
    45. long long n = num;
    46. n = -n;
    47. string s = to_string(n);
    48. a[0] = s.size();
    49. for(int i = 0;i < int(s.size());i++)
    50. {
    51. a[a[0] - i] = -(s[i] - '0');
    52. }
    53. return *this;
    54. }
    55. return *this = to_string(num);
    56. }
    57. int& operator [] (int x)
    58. {
    59. return a[x];
    60. }
    61. size_t size()
    62. {
    63. return a[0];
    64. }
    65. bool operator < (Int b) const
    66. {
    67. if(this->a[0] != b[0]) return this->a[0] < b[0];
    68. for(int i = this->a[0];i >= 1;i--)
    69. {
    70. if(this->a[i] != b[i])
    71. {
    72. return this->a[i] < b[i];
    73. }
    74. }
    75. return false;
    76. }
    77. bool operator > (Int b) const
    78. {
    79. if(this->a[0] != b[0]) return this->a[0] > b[0];
    80. for(int i = this->a[0];i >= 1;i--)
    81. {
    82. if(this->a[i] != b[i])
    83. {
    84. return this->a[i] > b[i];
    85. }
    86. }
    87. return false;
    88. }
    89. bool operator == (Int b) const
    90. {
    91. if(this->a[0] != b[0]) return false;
    92. for(int i = this->a[0];i >= 1;i--)
    93. {
    94. if(this->a[i] != b[i])
    95. {
    96. return false;
    97. }
    98. }
    99. return true;
    100. }
    101. bool operator != (Int b) const
    102. {
    103. return !(*this == b);
    104. }
    105. bool operator <= (Int b) const
    106. {
    107. if(this->a[0] != b[0]) return this->a[0] <= b[0];
    108. for(int i = this->a[0];i >= 1;i--)
    109. {
    110. if(this->a[i] != b[i])
    111. {
    112. return this->a[i] <= b[i];
    113. }
    114. }
    115. return false;
    116. }
    117. bool operator >= (Int b) const
    118. {
    119. if(this->a[0] != b[0]) return this->a[0] >= b[0];
    120. for(int i = this->a[0];i >= 1;i--)
    121. {
    122. if(this->a[i] != b[i])
    123. {
    124. return this->a[i] >= b[i];
    125. }
    126. }
    127. return false;
    128. }
    129. Int operator + (Int y)
    130. {
    131. Int z;
    132. z[0] = 0;
    133. if(y[0] == 1 && y[1] == 0)
    134. {
    135. return *this;
    136. }
    137. for(int i = 1,g = 0;;i++)
    138. {
    139. if(!g && i > a[0] && i > y[0]) break;
    140. int t = g;
    141. if(i <= a[0]) t += a[i];
    142. if(i <= y[0]) t += y[i];
    143. z[++z[0]] = t % 10;
    144. g = t / 10;
    145. }
    146. return z;
    147. }
    148. Int operator + (long long y)
    149. {
    150. return *this + Int(y);
    151. }
    152. Int& operator += (Int y)
    153. {
    154. return *this = *this + y;
    155. }
    156. Int& operator += (long long y)
    157. {
    158. return *this = *this + Int(y);
    159. }
    160. Int operator ++ ()
    161. {
    162. return *this += 1;
    163. }
    164. Int operator - (Int y)
    165. {
    166. Int x = *this;
    167. bool flag = true;
    168. if(x < y)
    169. {
    170. swap(x,y);
    171. flag = false;
    172. }
    173. Int z;
    174. z[0] = 0;
    175. if(y[0] == 1 && y[1] == 0)
    176. {
    177. return *this;
    178. }
    179. for(int i = 1,g = 0;;i++)
    180. {
    181. if(!g && i > x[0] && i > y[0]) break;
    182. int t = g;
    183. if(i <= x[0]) t += x[i];
    184. if(i <= y[0]) t -= y[i];
    185. if(t >= 0)
    186. {
    187. z[++z[0]] = t;
    188. g = 0;
    189. }
    190. else
    191. {
    192. z[++z[0]] = t + 10;
    193. g = -1;
    194. }
    195. }
    196. while(!z[z[0]]) --z[0];
    197. if(z[0] <= 0)
    198. {
    199. z[0] = 1;
    200. }
    201. if(!flag)
    202. {
    203. for(int i = 1;i <= z[0];i++)
    204. {
    205. z[i] = -z[i];
    206. }
    207. }
    208. return z;
    209. }
    210. Int operator - (long long y)
    211. {
    212. return *this - Int(y);
    213. }
    214. Int& operator -= (Int y)
    215. {
    216. return *this = *this - y;
    217. }
    218. Int& operator -= (long long y)
    219. {
    220. return *this = *this - Int(y);
    221. }
    222. Int operator -- ()
    223. {
    224. return *this -= 1;
    225. }
    226. Int operator * (long long y)
    227. {
    228. if(y == 0) return Int("0");
    229. bool flag = false;
    230. if(y < 0)
    231. {
    232. y = -y;
    233. flag = true;
    234. }
    235. Int z;
    236. z[0] = 0;
    237. int u = 0;
    238. for(int i = 1;i <= a[0];i++)
    239. {
    240. int t = a[i] * y + u;
    241. z[i] = t % 10;
    242. z[0]++;
    243. u = t / 10;
    244. }
    245. while(u > 0)
    246. {
    247. z[++z[0]] = u % 10;
    248. u /= 10;
    249. }
    250. if(flag)
    251. {
    252. for(int i = 1;i <= z[0];i++)
    253. {
    254. z[i] = -z[i];
    255. }
    256. }
    257. return z;
    258. }
    259. Int operator * (Int y)
    260. {
    261. Int z;
    262. z[0] = 0;
    263. for(int i = a[0];i >= 1;i--)
    264. {
    265. z = z * 10 + y * a[i];
    266. }
    267. for(int i = MAXN;i >= 1;i--)
    268. {
    269. if(z[i] != 0)
    270. {
    271. z[0] = i;
    272. return z;
    273. }
    274. }
    275. return Int(0);
    276. }
    277. Int& operator *= (Int y)
    278. {
    279. return *this = *this * y;
    280. }
    281. Int& operator *= (long long y)
    282. {
    283. return *this = *this * y;
    284. }
    285. Int operator / (long long y)
    286. {
    287. Int z;
    288. z[0] = 0;
    289. long long r = 0;
    290. bool zero = true;
    291. for(int i = a[0];i >= 1;i--)
    292. {
    293. long long t = r * 10 + a[i];
    294. if(zero && t / y) zero = false;
    295. if(!zero) z[++z[0]] = t / y;
    296. r = t % y;
    297. }
    298. reverse(z.a + 1,z.a + z[0] + 1);
    299. while(z[z[0]] == 0 && z[0] > 1) z[0]--;
    300. return z;
    301. }
    302. Int operator / (Int y)
    303. {
    304. Int z;
    305. z[0] = 0;
    306. return z;
    307. }
    308. Int& operator /= (long long y)
    309. {
    310. return *this = *this / y;
    311. }
    312. Int operator % (long long y)
    313. {
    314. return *this - *this / y * y;
    315. }
    316. Int& operator %= (long long y)
    317. {
    318. return *this = *this % y;
    319. }
    320. Int operator % (Int y)
    321. {
    322. return *this - *this / y * y;
    323. }
    324. Int& operator %= (Int y)
    325. {
    326. return *this = *this % y;
    327. }
    328. Int operator << (int n)
    329. {
    330. return *this * int(pow(2,n));
    331. }
    332. Int operator <<= (int n)
    333. {
    334. return *this = *this * int(pow(2,n));
    335. }
    336. Int operator >> (int n)
    337. {
    338. return *this / int(pow(2,n));
    339. }
    340. Int operator >>= (int n)
    341. {
    342. return *this = *this / int(pow(2,n));
    343. }
    344. };
    345. Int operator ++ (Int &x,int a)
    346. {
    347. return (x += 1) - 1;
    348. }
    349. Int operator -- (Int &x,int a)
    350. {
    351. return (x -= 1) + 1;
    352. }
    353. ostream& operator << (ostream& out,Int a)
    354. {
    355. if(a[a[0]] < 0)
    356. {
    357. out << "-";
    358. }
    359. for(int i = a[0];i >= 1;i--)
    360. {
    361. out << abs(a[i]);
    362. }
    363. return out;
    364. }
    365. istream& operator >> (istream& in,Int &a)
    366. {
    367. string s;
    368. in >> s;
    369. a = s;
    370. return in;
    371. }
    372. int mul[50];
    373. string s;
    374. int k;
    375. int a[30],b[30],vis[30],flag[15];
    376. void dfs(int j,int n)
    377. {
    378. for(int i = 1;i <= k;i++)
    379. {
    380. if(a[i] == n && !vis[i])
    381. {
    382. vis[i] = true;
    383. flag[b[i]] = true;
    384. dfs(j,b[i]);
    385. vis[i] = false;
    386. }
    387. }
    388. }
    389. int main()
    390. {
    391. cin >> s >> k;
    392. for(int i = 1;i <= k;i++)
    393. {
    394. cin >> a[i] >> b[i];
    395. }
    396. Int ans = 1;
    397. for(int i = 0;i < s.size();i++)
    398. {
    399. memset(flag,false,sizeof(flag));
    400. dfs(i,s[i] - '0');
    401. int cnt = 0;
    402. flag[s[i] - '0'] = true;
    403. for(int i = 0;i <= 9;i++)
    404. {
    405. cnt += flag[i];
    406. }
    407. ans *= cnt;
    408. }
    409. cout << ans << endl;
    410. return 0;
    411. }

     

  • 相关阅读:
    ES6中的Promise基础讲解
    /main/binary-i386/Packages 404 File not found
    【博客465】BGP(边界网关协议)-----BGP路由黑洞及路由反射器与联盟
    npm 常用的命令
    闭着眼睛安装Neoj4版本(5.12.0 Community windows)
    yum、apt-get、curl、wget和pip的使用范围
    Integer使用不当
    rabbitMq创建交换机,以及路由键绑定队列教程
    postgresql-视图
    kafka Consumer分析与速度特性
  • 原文地址:https://blog.csdn.net/weixin_68756152/article/details/133828552