- 博客(183)
- 资源 (1)
- 收藏
- 关注
原创 c++ , scoped enum, unscoped enum
#include <iostream>/* scoped enumerations and unscoped enumerations*/int main(){ { // unscoped enum enum Color : unsigned long long { Red = 2ULL, Green, blue }; Color c1 = ...
2018-12-01 17:40:00
878
原创 c++ RTTI, dynamic_cast, typeid
/* RTTI (Run-Time Type Information), 运行时类型信息 保护2部分 1: dynamic_cast 2: typeid*/#include <iostream>#include <typeinfo> struct Base{ virtual ~Base() {};};//
2018-12-01 17:21:08
219
原创 编程之美 1.2 中国象棋将帅问题
/*编程之美1.2 中国象棋将帅问题:利用1个字节来输出将帅的合法位置*//* 方法一:位运算*/#include using namespace std;#define LEFT(a) ((a)>>4)#define RIGHT(a) ((a) & 0x0F)#define ADD_LEFT(a) a =( (LEFT(a)+1<<4) | RIGHT(a))#
2013-10-29 20:06:45
648
原创 暴风影音2014校园招聘笔试题目-技术D卷
/* 暴风影音2014校园招聘笔试题目-技术D卷. 6. m*n的网格从左上角A点走到右下角B点,每次可走一格,只能往右或下走。 输出有多少种走法和所有路线数。*/#include #include #include using namespace std;int m = 2, n = 3;int* path;void printPath(){ int i; f
2013-10-19 10:10:32
691
原创 UVa 10739 - String to Palindrome
/*DP:编辑距离1.字符串为空或长度为1返回02.若子串为原串s的从i到j部分,记[i,j];若s[i] == s[j], 则[i,j] = [i+1, j-1];若不等 [i,j] = min([i+1,j-1], [i+1, j], [i, j-1]) + 1;*/#include #include #include #include using namespace s
2013-08-27 10:28:57
461
原创 sort
#include #include #include #include #include using namespace std;const int INF = 1<<30;const int MAXN = 100;int A[MAXN], n;int L[MAXN], R[MAXN]; // merge_sortint heap_size;#define left(i) (
2013-08-22 11:32:48
465
原创 UVa 10881 - Piotr's Ants
/*ch1, 例题5*/#include #include #include using namespace std;const int MAXN = 10004;char DIR[][10] = {"L", "R", "Turning"};struct ant{ int pos; int dir; bool operator < (const ant
2013-08-16 16:58:19
377
原创 UVa 1388 - Graveyard
/*ch1, 例题4*/#include #include #include using namespace std;int main(){ #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif // ONLINE_JUDGE int n, m; while(scanf("
2013-08-15 19:41:28
426
原创 UVa 11300 - Spreading the Wealth
/*ch1, 例题3代数分析 + 快速选择*/#include #include #include using namespace std;const int MAXN = 1000004;long long A[MAXN], B[MAXN];int n;int part(int x, int y){ int i=x-1, j; long long ke
2013-08-15 07:47:59
427
原创 UVa 11729 - Commando War
/*ch1, 例题2贪心,优先选择执行时间长的*/#include #include using namespace std;const int MAXN = 1000 + 4;int B[MAXN], J[MAXN];int idx[MAXN];bool cmp(int a, int b){ return J[a] > J[b];}int main(){
2013-08-14 19:04:20
426
原创 UVa 11292 The Dragon of Loowater
#include #include using namespace std;const int MAXN = 20000 + 4;int A[MAXN], B[MAXN];int main(){ #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif // ONLINE_JUDGE int
2013-08-13 11:33:50
524
原创 UVa 297 - Quadtrees
/*dfs+暴力,建立一个1024数组代表图像,接着dfs遍历,把每个黑色节点对应的地图区域设置为1.最好统计数组中1的个数*/#include #include #include #include #include using namespace std;char a[3000];char vis[1024];int st;//dfs返回值表示该子树在字符串中占用字符
2013-07-30 19:44:33
431
原创 UVa 540 - Team Queue
/*队列操作, 用了一个1000000的数组记录每个人所属team*/#include #include #include #include #include using namespace std;const int MAXT = 1004;const int HASH_SIZE = 1000004;const int BUFF_SIZE = 16
2013-07-30 17:32:21
398
原创 UVa 11234 - Expressions
/*首先建一个表达式树(二叉树),栈算法的表达式对应二叉树的后序遍历,根据例子发现队列算法的表达式对应二叉树的层序遍历序列的逆序列。*/#include #include #include #include using namespace std;const int MAXN = 10004;char v[MAXN];int l[MAXN], r[MAXN], n;int
2013-07-29 18:30:59
469
原创 UVa 11111 - Generalized Matrioshkas
/*栈操作,类似括号匹配*/#include #include #include #include using namespace std;const int BUFF_SIZE = 100004;int st[BUFF_SIZE], v[BUFF_SIZE];int fr;int main() { #ifndef ONLINE_JUDGE
2013-07-29 15:43:01
446
原创 UVa 442 - Matrix Chain Multiplication
/*栈操作*/#include #include #include #include using namespace std;const int MAXN = 26;const int BUFF_SIZE = 1024;int r[MAXN], c[MAXN];int n;char buff[BUFF_SIZE];int str[BUFF_SIZ
2013-07-29 11:43:37
435
原创 UVa 10152 - ShellSort
/*栈操作*/#include #include #include #include using namespace std;const int MAX_NAME = 84;const int MAXN = 204;char name[MAXN][MAX_NAME];char buff[MAX_NAME];int init[MAXN];int o
2013-07-29 10:36:54
355
原创 UVa 10050 - Hartals
/*简单的数组操作*/#include #include #include #include using namespace std;const int MAXN = 3654;int vis[MAXN];int n;int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #e
2013-07-28 19:53:26
395
原创 UVa 673 - Parentheses Balance
#include #include #include #include using namespace std;const int MAXN = 134;char st[MAXN];int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int T; sc
2013-07-28 19:28:40
449
原创 UVa 133 - The Dole Queue
/*练习下双向链表*/#include #include #include #include using namespace std;const int MAXN = 24;struct node { int pre, next;};node dq[MAXN];int N, k, m;int st1, st2;void init_queue(){ f
2013-07-28 11:20:55
383
原创 UVa 10785 - The Mad Numerologist
#include #include #include #include using namespace std;char letter[2][22] = {"AUEOI", "JSBKTCLDMVNWFXGPYHQZR"};int c[2] = {21, 5};char t[22];char out[212];int n;// k=0 vowel, k=1 consonant
2013-07-27 21:10:56
474
原创 UVa 755 - 487--3279 Or Poj 1002
UVa上没法提交这题,就去了Poj, poj上提交要略微修改。方法一:电话号码转换为数字后排序。#include #include #include #include using namespace std;const int MAXN = 100004;const int BUFF_SIZE = 30;int A[MAXN];int vis[MAXN];int n;c
2013-07-26 20:38:44
578
原创 UVa 10194 - Football (aka Soccer)
/* 排序,细心点就可以过*/#include #include #include #include using namespace std;const int MAXN = 34;const int TOURNAMENT_NAME = 104;const int TEAM_NAME = 34;const int BUFF_SIZE = 1024;c
2013-07-26 16:56:52
475
原创 UVa 400 - Unix ls
/*sort + printf格式控制*/#include #include #include #include #include #include #include using namespace std;const int MAXN = 104;const int MAXL = 64;char files[MAXN][MAXL];int idx[MAXN];int
2013-07-26 12:01:16
412
原创 UVa 152 - Tree's a Crowd
/*O(n*n)算法,因为数不大,使用小技巧直接比较中间结果,不去开根号*/#include #include #include #include #include #include #include using namespace std;const int MAXN = 5004;double X[MAXN], Y[MAXN], Z[MAXN
2013-07-26 10:57:41
376
原创 UVa 299 - Train Swapping
/*求逆序对*/#include #include #include #include #include using namespace std;const int MAXL = 54;int A[MAXL];int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif
2013-07-25 18:43:43
389
原创 UVa 156 - Ananagrams
/*各种排序,用了一个小技巧,只对序号排序,字符串不移动*/#include #include #include #include #include #include using namespace std;const int MAXN = 10002;char dict[MAXN][22], words[MAXN][22];int ans[MAXN], idx[MAXN]
2013-07-25 18:38:40
422
原创 UVa 567 - Risk
/*图论 : Floyd算法*/#include #include #include #include #include using namespace std;const int MAXN = 21;int G[MAXN][MAXN];void floyd(){ for(int k=1; k<MAXN; k++) { for(int i=1; i
2013-07-21 18:32:17
413
原创 使用 not exists, not in 须小心
not exists 和 not in 对空值返回结果不同.product_type_id 为空时,not exists 有返回,而not in没有返回值。NOT EXISTS:SELECT product_type_id, nameFROM product_types outerWHERE NOT EXISTS (SELECT 1 FROM products i
2013-07-20 12:35:42
470
原创 UVa 10183 - How Many Fibs?
/*数学:Fibonacci数列 + 大数模板*/#include #include #include #include #include using namespace std;#define MAX_N 1000 //最大位数//大数struct bign { char s[MAX_N]; int len; bign
2013-07-18 16:57:27
437
原创 UVa 10334 - Ray Through Glasses
/*数学:递归,大数,Fabonacci数列。没注意是Fabonacci数列,不过也得到了一个递归式。当n为奇数时, a[n] = a[n-1], b[n] = a[n-1] + b[n-1]当n为偶数时, a[n] = a[n-1] + b[n-1], b[n] = b[n-1]其中, a[n]为从顶部玻璃反射回的光, b[n]为从底部玻璃反射回的光。总数量为 a[n]
2013-07-18 12:18:04
438
原创 UVa 106 - Fermat vs. Pythagoras
/*数学:毕达哥拉斯数, GCD如果u, v不含公因子,且都不是奇数,则 u*u - v*v, 2uv, u*u + v*v 是毕达哥拉斯数。*/#include #include #include using namespace std;const int MAXN = 1000004;int vis[MAXN];int n;int gcd(int
2013-07-17 11:39:12
429
原创 UVa 128 - Software CRC
/*数学: 模运算*/#include #include #include using namespace std;const int G = 34943;const int ED = (256*256)%G;int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif
2013-07-16 22:33:49
420
原创 UVa 138 - Street Numbers
/*数学:暴力*/#include #include #include using namespace std;int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int cnt = 0; for(int i=2; i<100
2013-07-16 16:22:05
466
原创 UVa 10006 - Carmichael Numbers
/*数学:素数 + 模运算Carmichael Number:1)非素数2)通过 Fermat Pass所以,程序要完成两个工作。1) 判断n是否为素数2) 测试对于 2 <= a <= n-1,是否满足 a^n mod n = a工作1:由于n很小,可以用筛素数法。工作2:求a^n mod n,可以使用分冶法优化。对于任务2还可以优化,a不必取所有 [2,n-
2013-07-16 16:20:11
468
原创 UVa 579 - ClockHands
/*数学,钟的角度问题*/#include #include #include using namespace std;int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int h, m; while(scanf("%d:%d", &h, &m) =
2013-07-13 10:36:30
361
原创 UVa 550 - Multiplying by Rotation
/*数学,模拟n进制乘法*/#include #include #include using namespace std;int s, a, b;int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif while(scanf("%d%d
2013-07-12 13:31:33
388
原创 UVa 10392 - Factoring Large Numbers
/*数学:筛素数*/#include #include #include using namespace std;const int MAXN = 1000002;const int MAXP = 80000;int vis[MAXN];int prime[MAXP];int cnt=0;long long num;void get_pr
2013-07-12 09:48:21
401
原创 UVa 10879 - Code Refactoring
/*数学:练一下筛素数*/#include #include #include using namespace std;int vis[3500];int prime[2000];int cnt=0;int num;void get_prime(){ int m = sqrt(3500); int i; for(i=2; i<m; i++) if(
2013-07-11 22:15:09
398
原创 UVa 408 - Uniform Generator
/*数学:求最大公约数*/#include #include #include using namespace std;int gcd(int a, int b){ return b? gcd(b, a%b) : a;}int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin);
2013-07-10 21:53:40
344
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人