UVa 11401 – Triangle Counting//計數

  簡單的計數,只要做到不重,不漏,就應該能過了。  下面是代碼,因為是厚白數上的例題,所以自己很沒譜。   #include<iostream>using namespace std;long long ans[10000010];int main(){ ans[3]=0; for(long long i=4;i<=10000010;i++) ans[i]=ans[i-1]+((i-1)*(i-2)/2-(i-1)/2)/2; int n;

UVa 784 – Maze Exploration//DFS

水題一道,直接DFS。下面是代碼:#include<stdio.h>#include<string.h>char map[35][85];//int vis[35][85];int move[4][2]={{1,0},{-1,0},{0,1},{0,-1}};int h;void dfs(int x,int y){ for(int i=0;i<4;i++) { int dx=x+move[i][0]; int

705 – Slash Maze//搜尋

刷這道題的時候發現自己和大牛的差距了。剛開始我想的是如何類比這個迷宮,想來想去沒想出什麼就去網上搜大牛的想法。結果是用方格來替'\'和'/',和我想的剛好相反。可是我卻放棄了思考。哎,下次堅決不能這樣了。言歸正傳,剛開始時用一個2*2的方格來類比斜杠,但是要判斷遞迴的方向,很是麻煩。共有8個方向需要判斷。所以換了用3*3的來類比這個斜杠。這樣只需要記下遍曆過的方格的個數就可以得到答案了。下面是代碼:#include<stdio.h>#include<string.h>#d

Poj 2186- Popular Cows//kosaraju

Popular CowsTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 19089 Accepted: 7678DescriptionEvery cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M <=

Uva 10369 – Arctic Network//kruskal

Problem C: Arctic NetworkThe Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio

Uva 658 – It’s not a Bug, it’s a Feature!//最短路

  It's not a Bug, it's a Feature! It is a curious fact that consumers buying a new software product generally do not expect the software to be bug-free. Can you imagine buying a car whose steering wheel only turns to the right? Or a CD-player that

10099 – The Tourist Guide//floyd

Problem DThe Tourist GuideInput: standard inputOutput: standard output Mr. G. works as a tourist guide. His current assignment is to take some tourists from one city to another. Some two-way roads connect the cities. For each pair of neighboring

657 – The die is cast//搜尋

這道題搜尋裡面套搜尋,注意如何判斷兩個X是否相連調試注意各種細節。代碼見下:#include<stdio.h>#include<string.h>#include<algorithm>#define MAXN 105using namespace std;char map[MAXN][MAXN];int vis[MAXN][MAXN];int visx[MAXN][MAXN];int ans[MAXN];int w,h;int cnt;int move[4][

439 – Knight Moves//bfs

尼瑪,原來國際象棋的騎士和我們象棋的馬的走法差不多啊。這道題直接bfs做。下面是代碼:#include<cstdio>#include<cstring>#include<iostream>#define MAXN 10using namespace std;struct node{ int x; int y; int step; node(){} node(int a,int b,int c):x(a),y(b),step(c){

138 – Street Numbers//暴力or解方程

先bs下自己吧。這道題可以先打表,在提交。剛開始寫的二分有點問題,我先找到的是n,然後再找m。其實是先找到m,然後再找n。另一種解法是解方程,解佩爾方程。不管是暴力還是解方程都要先找出運算式。由題意可得n*(n+1)/2=x*(x+1)/2-n*(n+1)+n;化簡可得n*n/2=x*x+x。然後將其變形為標準的佩爾方程,然後再用遞推求解。下面是二分的代碼:#include<iostream>#include<cstdio>using namespace

532 – Dungeon Master//bfs

題目給的是個三維的圖形,那麼就開一個三維的數組,然後用bfs就ok啦!下面是代碼:#include<iostream>#include<stdio.h>#include<cstring>using namespace std;#define MAXN 31struct node{ int l; int r; int c; int t; node(){} node(int x,int y,int z,int

uva 10050 – Hartals//水題

   這道題有點水,直接上代碼吧!  #include<stdio.h>#include<string.h>#define MAXN 3700int hash[MAXN];int main(){ int n,m,d,h; scanf("%d",&n); while(n--) { int ans=0; scanf("%d",&d); scanf("%d",&m);

10305 – Ordering Tasks//拓撲排序

/* 小小的吐槽一下,資料有點問題,題目說的以n=0,m=0 結束。可是測試的資料應該是n=0,m!=0結束的,Orz, wa了多次*/#include<cstdio>#include<cstring>using namespace std;const int maxn = 105;int G[maxn][maxn];int vis[maxn];int topo[maxn];int n,m,t;void dfs(int u){ vis[u] = 1;

196 – Spreadsheet//dfs

/*連續兩道題目的資料有問題,Ora。剛開死將這道題想簡單了,直接類比做的,額...*/#include<cstdio>#include<cstring>#include<string>#include<iostream>#include<cstdlib>using namespace std;const int maxn = 1001;const int Min = -100000000;int

10167 – Birthday Cake//枚舉

/*簡單的枚舉*/#include<cstdio>#include<cstring>using namespace std;int a[4][2];int main(){ int N; while(scanf("%d",&N) && N) { for(int i = 0; i < 2*N; i++) { int x,y;

567 – Risk//bfs

因為沒有權值,所以不用使用Floyd演算法求最短路。直接用bfs做。。。#include<cstdio>#include<cstring>using namespace std;const int maxn = 21;int G[maxn][maxn];int vis[maxn][maxn];struct node{ int level; int u;} q[maxn*maxn];int bfs(int s,int e){ int front = 1;

10034 – Freckles\\MST

模板題,可以用kruskal,也可以用最短路。#include<cstdio>#include<string>#include<algorithm>#include<cmath>using namespace std;const int maxn = 5555;int u[maxn],v[maxn],p[maxn];double map[105][2];struct node{ int id; double w;}

10048 – Audiophobia\\Floyd

  Problem B: Audiophobia Consider yourself lucky! Consider yourself lucky to be still breathing and having fun participating in this contest. But we apprehend that many of your descendants may not have this luxury. For, as you know, we are the

10397 – Connect the Campus

Problem EConnect the CampusInput: standard inputOutput: standard outputTime Limit: 2 secondsMany new buildings are under construction on the campus of the University of Waterloo. The university has hired bricklayers, electricians, plumbers, and a

UVa 11538 – Chess Queen//計數

                                                                      給定的m*n的棋盤,放置黑白皇后的方式從三個方面考慮。行,列,對角線。行:選取一個皇后放置一個皇后有m*n中方式,接下來放置另一個皇后,有(n-1)中方式,所以按行考慮有n*m*(n-1)種方式。列:同理可得有n*m*(m-1)中方式。對角線: 對角線有兩個方向的,”/“和”\“兩個方向,先考慮一個方向。                 每條對角線的長度為:

總頁數: 61357 1 .... 13465 13466 13467 13468 13469 .... 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.