01 2016 档案
摘要:X-Y Problem 对于X-Y Problem的意思如下: 1)有人想解决问题X2)他觉得Y可能是解决X问题的方法3)但是他不知道Y应该怎么做4)于是他去问别人Y应该怎么做? 简而言之,没有去问怎么解决问题X,而是去问解决方案Y应该怎么去实现和操作。于是乎: 1)热心的人们帮助并告诉这个人Y应该
阅读全文
摘要:想法: 初始化三個數L=0/1, M=1/1, R=1/0,設輸入的分數為a: 如果a<M,那麼要往左邊走, R = M; M = (L分子+M分子)/(L分母+M分母); 如果a>M,往右邊走, L = M; M = (R分子+M分子)/(R分母+M分母); 如果a==M,停止。 這題和二分搜尋很
阅读全文
摘要:--> 从而避免了输出格式; 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 int main() 9 {10 int t, count = 0;11 ...
阅读全文
摘要:《美丽心灵》(A Beatiful Mind)——经典台词美丽心灵经典台词
阅读全文
摘要:为什么要循规蹈矩呢?如下: 1 #include 2 #define max 2000005 3 4 int main() 5 { 6 int n, age[max], i, j, m; 7 while(scanf("%d", &n), n) 8 { 9 ...
阅读全文
摘要:已有的数据结构装不下数据,或者不能处理现有的数据,那就必须要思考其他的辅助手段,辅助结构; 1 #include 2 #include 3 #include 4 using namespace std; 5 6 vector order; 7 map freq; 8 9 int main(...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 const char kTable[] = "2223334445556667Q77888999Z...
阅读全文
摘要:题意为,给你一个序列, 每次交换两个相邻的数使序列为递增的序列, 求最小的交换次数。首先我们可以看出。 最少的交换次数肯定得用归并排序来求了。实际上归并排序的交换次数就是这个数组的逆序对个数,为什么呢?我们可以这样考虑:归并排序是将数列a[l,h]分成两半a[l,mid]和a[mid+1,h]分别进...
阅读全文
摘要:逆序数的几种求法白话经典算法系列之九 从归并排序到数列的逆序数对(微软笔试题)
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 deque cir; 9 long P, C, cas = 0;10 11 while(scanf("%ld%l...
阅读全文
摘要:题目:给你n个方块,有四种操作: 1.move a onto b,把a和b上面的方块都放回原来位置,然后把a放到b上面; 2.move a over b,把a上面的放回原处,然后把a放在b所在的方块堆的上面; 3.pile a onto b,把b上面的放回原来位置,然后把a所在的堆...
阅读全文
摘要:想法: 將問題簡化為求1~m 0的總數,以及1~n 0的總數,然後最後再相減。 求1~n 0的總數,要將n分別算每個位數0的個數,舉例如30324:先從右邊第一位'4'開始,其左邊為3032,表示1~30320在"第一位"總共有3032*1=3032個0換第二位數'2',其左邊為303,表示總共...
阅读全文
摘要:UVa 498: Polly the Polynomial | MathBlog 1 #include 2 #include 3 using namespace std; 4 5 int temp, c[10000]; 6 7 int main() 8 { 9 int n;10 ...
阅读全文
摘要:题目大意:给出A,B两个点的坐标,以及T,每次找到A、B的四等分点C,D,然后以AB/2为边长,C,D为顶点,构建一个等边三角形,E为另外一个顶点,然后再对C,E;E,D做同样的操作,直到构建的等边三角形的边长小于T时。输出所有过程中的点,按照x坐标排序,相同的按照y坐标。解题思路:dfs模拟,用a...
阅读全文
摘要:題目意思:讀取一數字,此數字最大有1000位。計算該數字是否為九的倍數?如是,再計算其階層數。 ※判斷是否為九的倍數:所有位數相加 ÷ 9=0,即為九的倍數。 ※計算階層數:所有位數相加後得出的第一個總和為一階,依此類推直到該數字無法再計算總和。 Example 1: 999 => 27(9+9+...
阅读全文
摘要:1 #include 2 #define ll long long 3 4 const ll MOD = 1e9; 5 6 int main() 7 { 8 ll N, M; 9 while(scanf("%lld%lld", &N, &M) != EOF)10 {1...
阅读全文
摘要:1 //组合数学 2 //计算sum{i从右往左数的第一个非0数字,p 4 typedef long long ll; 5 6 ll sum(ll n) 7 { 8 ll ans = 0, x; 9 while(n)10 {11 x = n % 10;12...
阅读全文
摘要:1 #include 2 3 int main() 4 { 5 long int F, S, I, Count, Value, Max, J; 6 while(scanf("%ld %ld", &F, &S) && F) 7 { 8 if(F > S) ...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 void print(int i, int j) 6 { 7 if(i > j) { int temp = i; i = j; j = temp; } 8 9 int max ...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 const int SIZE = 13; 7 const int value[] = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500...
阅读全文
摘要:枚举法 1 #include 2 using namespace std; 3 4 int main() 5 { 6 int t, n, i, j, k; 7 scanf("%d", &t); 8 char f[10000][5]; 9 for(i = 0; i ...
阅读全文
摘要:找出步數與距離的關係即可得解。0步最多能抵達的距離是01步最多能抵達的距離是1(1)2步最多能抵達的距離是2(1 1)3步最多能抵達的距離是4(1 2 1)4步最多能抵達的距離是6(1 2 2 1)5步最多能抵達的距離是9(1 2 3 2 1)6步最多能抵達的距離是12(1 2 3 3 2 1)……...
阅读全文
摘要:程序运行时错误(运行时出错就是出现在程序运行过程中的),有很多种;比如:溢出、内存泄露、死循、乱用指针、数组越界(数组开小了?)、除以0错误、递归太深层(系统暴栈了)
阅读全文
摘要:题意:输入n,然后输入n个数字,,要在这n个数字中找出a,b,c,d。。满足a,b,c,d是不同元素,并且a+b+c=d。。。求出最大的d直接暴力时间复杂度为O(n^4)。。会超时。。所以需要一定技巧性的枚举原式转换成a+b=d-c;把n个数字从小到大排列。由于d要求最大。所以从最大开始枚举。遇到符...
阅读全文
摘要:题解:由于解太多,随机抓 A、B, 只要有符合就行了; (首先,Ax+By=0必须表示直线,即A、B不能同时为0;另外,要注意到直线不能过输入中的2N个点;检测点在直线的哪一侧,只需要简单的线性规划的知识) 1 #include 2 #include 3 4 int x[100], y[100...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 char in[1100]; 5 6 int main() 7 { 8 while(gets(in)) 9 {10 if(in[0] == '0' && in[1] == 0) bre...
阅读全文
摘要:题解: 观察a,b,c,d..字母后发现:a=|_oo__.__o|b=|_oo__._o_|c=|_oo__._oo|d=|_oo__.o__|e=|_oo__.o_o| 可以知道它是以二进位的方式表示,在把'a'的值(2^0+2^5+2^6=97)加起來后与ASCII表比较,刚好就是表上'a...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 int main() 5 { 6 long long a, b; 7 while(scanf("%lld%lld", &a, &b) != EOF) 8 { 9 if(a > b...
阅读全文
摘要:题目:给你一个矩阵和某些点,找到给的点所处连续的W区域的面积(八个方向)。分析:搜索。floodfill算法,利用搜索直接求解就可以了。说明:注意读入数据的格式。 1 #include 2 #include 3 using namespace std; 4 5 char map[105][10...
阅读全文
摘要:題意: 要確認畫面中有幾隻Eagles,每個pixel如果是'1'代表為一隻Eagles,但上下左右(包含斜角共8個方向)相連的'1'只能算是同一隻。想法: 使用DFS找'1'有幾個區域。 1 #include 2 using namespace std; 3 4 char image[30...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 #include 6 #define loop(i, n) for (int i = 0; i Graph[MAXX];16 bool visited[MAXX];17 int inacce...
阅读全文
摘要:题解: 一定有人获胜,非黑即白;获胜条件为:black是由 上走到下,white是由 左走到右; 1 #include 2 using namespace std; 3 int N; 4 char board[201][201]; 5 const int direction[][2] = {{-...
阅读全文
摘要:打开文件-->文件操作-->关闭文件打开文件Open() = open (, )磁盘文件名打开模式 (r, w, a, rb, wb, ab, r+)例如: >>> infile = open (“numbers.dat”, “r”) >>> infile = open (“music.mp3...
阅读全文
摘要:文件的基础文件存储在外部介质上的数据或信息的集合 。程序中的源程序数据中保存着数据图像中的像素数据…有序的数据序列。编码信息从一种形式转换为另一种形式的过程ASCII码UnicodeUTF-8…常用的编码Unicode跨语言、跨平台进行文本转换和处理对每种语言中字符设定统...
阅读全文
摘要:下列turtle库的简单常用指令forward(distance) #将箭头移到某一指定坐标left(angel) right(angel)penup() #提起笔,用于另起一个地方绘制时用,与pendown()配对使用goto(x,y)home()circle(radius)spe...
阅读全文
摘要:圆周率π是一个无理数,没有任何一个精确公式能够计算π值, π的计算只能采用近似算法。国际公认的PI值计算采用蒙特卡洛方法。蒙特卡洛(Monte Carlo)方法,又称随机抽样或统计试验方法。 当所求解问题是某种事件出现的概率,或某随机变量期望值时,可以通过某种“试验”的方法求解。 即:蒙特卡洛是...
阅读全文
摘要:题目大意:按照题目中的要求构造出一个序列,找出最短的子序列,包含1~k。解题思路:先根据题目的方法构造出序列,然后用Towpointer的方法,用v[i]来记录当前[l, r]中有几个i;当r移动时,出现v[i] == 1时, c++(用来记录有几个1~k的数字);当c == k 时,就要移动l,当...
阅读全文
摘要:思路:首先,如果这些点对称,那么它们的对称轴是x = m(m是所有点横坐标的平均值); 把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这个点是否在集合里面。 如果有一个不在的话,说明不能构成对称图形。 1 #include 2 #include 3 #incl...
阅读全文
摘要:一、用数组储存该位置的最高点即可(图形的连续点离散化),注意左边界及右边界的情况;注意:无论建筑物最左边是盖到哪里,你都得从1开始输出(输入输出都是integer,所以才能离散化); 1 #include 2 #include 3 using namespace std; 4 5 int ma...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int main(){ 8 //initialize for positive number 9 char h[...
阅读全文
摘要:题意:给出 n个数,找到尽量长的一个序列,使得该序列中没有重复的元素思路:对于该类段查找问题可以采用经典的滑动窗口方法,即维护一个窗口,窗口的左右边界用两个变量L,R代表,先增加R直到出现重复数字,再增加L,再增加R,直到R达到n滑动窗口 求解;当右端碰到有相同的数的时候,左端向右滑动一位数samp...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 int main() 9 {10 int N, number;11 string str;12 m...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main(int ac, char*av[]) 7 { 8 string keyboard = "`1234567890-=qwertyuiop[]\\a...
阅读全文
摘要:题意:输入一窜字符,然后输出每个字符在键盘上对应位置的前一位的字符,如输入W则输出Q,注意全部是大小写!其实就是破解密码类的问题。 1 #include 2 #include 3 using namespace std; 4 5 int main(int ac, char*av[]) 6 { ...
阅读全文
摘要:题目:编码翻译,有些字母有对应的数字,有的没有,如果连续对应的数字相同只输出一个。 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int rep( char c ) 7 { 8 sw...
阅读全文
摘要:题意:有一个键盘坏了 会在你不知道的情况下按下home或者end 给你这个键盘的实际输入 要求输出显示器上的实际显示解析:输入最大5MB 直接数组检索肯定会超时,用数组模拟链表 next数组表示显示屏中s[i]右边的字符编号,变量cur模拟光标,即当前光标位于s[cur]的右边。 变量l...
阅读全文
摘要:题意:给定一个n个整数的数组,进行多次查询,每次查询输出第k个v的位置。题解:定义map >mm;那么mm[i][j]表示的就是第j+1个i的值的位置。为什么?我们将每个v映射成map中的一个键,用变长数组vector保存v的所有位置;那么mm[v]对应的就是vector,就是所有v的位置,然后查询...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int main() 8 { 9 int cases, cols, northRow, southRow;10 cin >> ca...
阅读全文
摘要:经典问题,矩形面积并。解法:一、矩形分割,每个矩形的两个横坐标和两个纵坐标排序,这样得到2n*2n个区间,对这些区间依次判断是否包含在n个矩形中间即可。 二、扫描线。具体还没实现过。详见:http://www.algorithmist.com/index.php/UVa_688另:http://...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 int main() 6 { 7 unsigned C, N, tot_gra, aver, abo_c, gra[10010]; 8 float perc; 9 int...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 long long Median, arr[10010]; 6 7 8 int main() 9 {10 int i, cur_index, count, isOdd;11 ...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 int seq[3001], diff[3001]; 7 8 int main() 9 {10 int n, i, j, flag, min_index;11 ...
阅读全文
摘要:1 /* 2 * Author: Quickgrid ( Asif Ahmed ) 3 * Site: https://quickgrid.wordpress.com 4 * Problem: UVA 488 ( Triangle Wave ) 5 */ 6 #include 7 8 ...
阅读全文

浙公网安备 33010602011771号