POJ 1915 雙向廣搜

//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

hdu 2601(An easy problem)

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

hdu1062(Text Reverse)

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

給定一個鏈表的頭指標,要求只遍曆一次,將單鏈表中的元素順序反轉過來

//使用了三個指標,每次修改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

交換兩個數的函數int swap(int &a,int &b)

         最近突然想到以前看的交換兩個整數的巧妙寫法的限制條件忘了,所以就再看了一遍:#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<<"

尋找最大的K個數–遞迴解法

演算法思想:使用快排中的思想,隨機從數組中選擇一個元素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

HDU 1102(最小產生樹)

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

編程珠璣–如何使用位邏輯運算(例如不、或、移位)來實現位向量

首先說明一下,假設使用的是8bit的資料類型(32bit的不好畫),資料是怎麼排列的:然後去理解下面的代碼:#define BITSPERWORD 32 //表示一個整型含有32個bit#define SHIFT 5//單位位移量#define MASK 0x1F//掩碼#define N 10000000//表示有1000萬個數int

hdu 3925 Substring(類比)

題目連結: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.

NOJ1635看望朋友

#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

POJ 3126 廣搜

#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

tzc3109 兩圓外公切線之交

題目連結:tzc3109方法:計算幾何思想:當兩個圓的半徑相同或者兩圓關係為內含時不存在外公切線交點。當存在外公切線交點時,由於知道兩半徑,而外公切線與兩圓心夠成的直線及圓心與切點的連線所夠成的圖形中,得到交點到兩圓圓心的向量之比 等於半徑之比,從而(x-o1.x,y-o1.y)=k(x-o2.x,y-o2.y)。可惜這向量的關係很久沒用了,被我給忘記了,用距離+斜率聯立方程,既麻煩,又容易出錯。代碼:#include <iostream>#include <cmath>

tzc1051 A × B problem

題目:tzc1051方法:大數乘法  大數乘大數代碼:#include <iostream>#include <cstring>using namespace std;void mult(char a[],char b[],char s[]){int i,j,k=0,alen,blen,sum=0,res[500][500]={0},flag=0;char result[500];alen=strlen(a);blen=strlen(b); for

pku1899Farmer Bill’s Problem

題目:pku1899 題意:已知一長方形麥地的長、寬,在它裡面有一些圓形的UFO,用平行於x,y軸的長方形把UFO圍起來,並使其面積最小, 從而使可以收割的面積最大。如果兩個長方形相交,需將兩者合并。方法:計算幾何(矩形相交)+DFS 代碼:該代碼參考何長兵的部落格 //1 <= x, y <= 1000 0 <= N <= 100. #include <iostream>using namespace std;struct point{ int

實驗四 編寫求解斐波那契序列的應用程式

實驗目的在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、建立斐波

poj1915 Knight Moves

題目:       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

hdu 1068(最大獨立集)

Girls and Boys Time Limit : 20000/10000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 2   Accepted Submission(s) : 1Font: {ProFont('Times New Roman')}">Times New Roman | {ProFont('Verdana')}">Verdana |

hdu1078FatMouse and Cheese

 題目連結:hdu1078 代碼:dfs // each time he can run at most k locations to get into the hole before being caught by Top Killer.//Given n, k, and the number of blocks of cheese at each grid location,//compute the maximum amount of cheese FatMouse can eat

hdu1002A + B Problem II

題目:hdu1002 總結:本題之所以會WA幾次,是由於沒有把 system("pause"); 刪除,這是應該注意的地方。雖然杭電等網站支援system, 但是程式會運行到這句話,就會出現wrong answer,因此,一般要把這句話刪除再提交。 代碼: //You may assume the length of each integer will not exceed 1000.#include <iostream>#include <string>using

高精度計算模板

**********************************高精度加,減,乘,除,模數,模板**********************************/#include <iostream>#include <string>using namespace std;inline int compare(string str1, string str2){ if(str1.size() > str2.size())

總頁數: 61357 1 .... 24186 24187 24188 24189 24190 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.