Time of Update: 2018-12-03
最近Functional Programing似乎很熱,7月份的《程式員雜誌》也兩天篇文章是專門講述FP的。 Funtional Programming(函式程編)是一種寫傳統的Imperative(命令式編程)有著不一樣的思考方式。通過對FP的學習可以更好是從[怎麼樣解決問題這個角度]去分析問題。就我最近的瞭解,可以給FP打下以下幾個tag: 1,FP的特徵,以及功能是體現是通過High-Order Function以及Lazy
Time of Update: 2018-12-03
//10224045c00h00g1915Accepted1328K79MSC++2493B2012-05-22 11:35:10#include<iostream>#include<queue>using namespace std;int mat[305][305];int d1[305][305];//headint d2[305][305];//tailstruct Node{int x,y;};int N,n;int res;bool
Time of Update: 2018-12-03
今天無意中在CSDN的論壇上看到一個文章,文章的主題是:《剛看完C++的文法部分,下一步怎麼學?》。這個主題在論壇上是時常看到的,可見受此困惑的人還是頗多的。常見回複一般不外乎兩類:一類是,繼續深入學習。另一類是:動手編程,實踐。其實這兩類回複都應該是正確的,但似乎又不是提問者真正想要的,要不然這個問題也不會一而再,再而三地被提出了。
Time of Update: 2018-12-03
An easy problemTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1875 Accepted Submission(s): 409Problem DescriptionWhen Teddy was a child , he was always thinking about some simple math
Time of Update: 2018-12-03
Text ReverseTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3625 Accepted Submission(s): 1348Problem DescriptionIgnatius likes to write words in reverse way. Given a single line of text
Time of Update: 2018-12-03
//使用了三個指標,每次修改pnext指向pcurrent,然後移動三個指標#include<iostream>using namespace std;struct Node{int data;Node* next;};int a[5]={1,2,3,4,5};int main(){Node *head;head=(Node *)malloc(sizeof(Node));head->next=NULL;for(int i=0;i<5;i++){Node
Time of Update: 2018-12-03
最近突然想到以前看的交換兩個整數的巧妙寫法的限制條件忘了,所以就再看了一遍:#include<iostream>using namespace std;int a[]={1,2,3,4};void swap(int &a,int &b){a=a^b;b=a^b;a=a^b;}int main(){int m=1,n=2;swap(m,n);swap(a[1],a[1]);cout<<m<<"
Time of Update: 2018-12-03
這是在編程珠璣的習題上看到的,P214第四題節點的定義如下:struct node{int val;node *next;node(int v,node *p){val=v; next=p;}};另外初始化的過程中,初始化頭結點,head=new node(maxval,0)其中maxval表示一個最大值通常的插入函數都會這樣來寫:void insert(int t){node* before=NULL;node* p=head;while(p->val<t){before=p;p=
Time of Update: 2018-12-03
演算法思想:使用快排中的思想,隨機從數組中選擇一個元素x,將數組元素分成兩部分Sa和Sb,其中Sa>x,Sb<=x,這時,有兩種可能性:1. Sa中元素個數小於K,Sa中所有的數和Sb中最大的K-length(Sa),就是S中最大的K個數;2. Sa中元素個數大於或者等於K,則需要返回Sa中最大的K個數。不斷進行遞迴,能夠得到問題的解。//尋找最大的K個數#include<iostream>#include<vector>using namespace
Time of Update: 2018-12-03
Constructing RoadsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2666 Accepted Submission(s): 911Problem DescriptionThere are N villages, which are numbered from 1 to N, and you should
Time of Update: 2018-12-03
題目連結: tzc3056方法:計算幾何 注意:本題在輸出結果的時候要將資料強制轉換成整型,不能用%.0lf輸出,否則會WA。代碼:#include <iostream>#include <cmath>using namespace std;const double eps=1e-10;struct point{ double x,y; };struct line{ double a,b,c; };point point_about_line(point
Time of Update: 2018-12-03
首先說明一下,假設使用的是8bit的資料類型(32bit的不好畫),資料是怎麼排列的:然後去理解下面的代碼:#define BITSPERWORD 32 //表示一個整型含有32個bit#define SHIFT 5//單位位移量#define MASK 0x1F//掩碼#define N 10000000//表示有1000萬個數int
Time of Update: 2018-12-03
題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=3925題目大意:給定一個大數a,和小數b,問a最少加上多少使得a中含有子串b。解題思路:讓b*1,b*10,b*100與a想減,對每次減的結果取最小值。測試資料:1001340 134123456 2349 29999 11110 114444 11119 1代碼:#include <iostream>#include <stdio.h>#include <stdlib.
Time of Update: 2018-12-03
#include <string.h>#include <iostream>using namespace std;#define MAX_VERTEX_NUM 101#define INFINITY 0x11111111#define TRUE 1#define FALSE 0typedef struct{ //int info;}VertexType;typedef struct{ int val; //int
Time of Update: 2018-12-03
#include<iostream>#include<queue>using namespace std;int a,b,n,num;int lef[4];int rig[4];int mid[4];int visited[10005];int d[10005];int getnum(int aa[]){return 1000*aa[0]+100*aa[1]+10*aa[2]+aa[3];}//這個函數寫錯了void putin(int bb,int
Time of Update: 2018-12-03
題目連結:tzc3109方法:計算幾何思想:當兩個圓的半徑相同或者兩圓關係為內含時不存在外公切線交點。當存在外公切線交點時,由於知道兩半徑,而外公切線與兩圓心夠成的直線及圓心與切點的連線所夠成的圖形中,得到交點到兩圓圓心的向量之比 等於半徑之比,從而(x-o1.x,y-o1.y)=k(x-o2.x,y-o2.y)。可惜這向量的關係很久沒用了,被我給忘記了,用距離+斜率聯立方程,既麻煩,又容易出錯。代碼:#include <iostream>#include <cmath>
Time of Update: 2018-12-03
題目:pku1899 題意:已知一長方形麥地的長、寬,在它裡面有一些圓形的UFO,用平行於x,y軸的長方形把UFO圍起來,並使其面積最小, 從而使可以收割的面積最大。如果兩個長方形相交,需將兩者合并。方法:計算幾何(矩形相交)+DFS 代碼:該代碼參考何長兵的部落格 //1 <= x, y <= 1000 0 <= N <= 100. #include <iostream>using namespace std;struct point{ int
Time of Update: 2018-12-03
========================== 功能:選擇排序(由小到大) 返回:指向鏈表表頭的指標==========================*//* 選擇排序的基本思想就是反覆從還未排好序的那些節點中, 選出索引值(就是用它排序的欄位,我們取學號num為索引值)最小的節點, 依次重新組合成一個鏈表。 我認為寫鏈表這類程式,關鍵是理解: head儲存的是第一個節點的地址,head->next儲存的是第二個節點的地址; 任意一個節點p的地址,只能通過它前一個節點的next來求
Time of Update: 2018-12-03
實驗目的在C語言環境下(Turbo C或VC)編寫一個簡單的隊列管理的應用程式。通過本實驗,使學生能夠在C語言環境下熟練地編寫基本的應用程式。實驗意義通過本實驗,使學生能夠進一步理解隊列的結構和特點,熟悉隊列的使用方法。實驗背景4階斐波那契序列如下:f0=f1=f2=0, f3=1,…,fi=fi-1+fi-2+fi-3+fi-4,利用容量為k=4的迴圈隊列,構造序列的前n+1項(f0, f1 , f2 ,… fn ),要求滿足fn ≤200而fn+1 >200。實驗步驟及要求1、建立斐波
Time of Update: 2018-12-03
題目: http://poj.grids.cn/problem/1915/代碼: #include<iostream>using namespace std;int n,l;int a,b,c,d;int move[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}};int visited[310][310];int queue[100000][2];int num;void