Time of Update: 2018-12-04
1.首先要保證圖連通,那麼圖中奇度數的點必須是0個或者2個,此外還要判讀是否可以連通。#include <iostream>using namespace std;int n,m;int du[1005],father[1005],sum[1005];int find(int x){if(x!=father[x]) return father[x]=find(father[x]);return x;}void lianjie(int x,int y){int a=find(x),b=
Time of Update: 2018-12-04
迴路條件:1.所有點的度數必須為偶數。2.圖必須連通。3.圖必須首尾相接。思路:先統計度數,度數全為偶數,則找任意一點一路搜下去,並將搜到的邊儲存, 如果最後儲存的邊不足n條,說明圖不連通,如果是n條,判讀是第一條和最後一條是否相接。#include <iostream>#include <cstring>#include <vector>using namespace std;struct edge{int x,y;};int a[55][55],du[
Time of Update: 2018-12-04
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=17681 -1 0 0 -4 1 -1 0 0 -4 1 -1 0 0 -42 3 -2 -3 2 2 3 -2 -3 2 2 3 -2 -3 24 1 -1 5 0 -> 4 1 -1 5 0 4 1 -1
Time of Update: 2018-12-04
題意:輸入一個進位b,在輸入兩個基於b進位的大整數 x,y ,求x%y的b進位結果。http://162.105.81.212/JudgeOnline/problem?id=2305函數:String st = Integer.toString(num, base); // 把num當做10進位的數轉成base進位的st(base <= 35).int num = Integer.parseInt(st, base); //
Time of Update: 2018-12-04
dp[l][i][j] 表示第l個分組以第i個字母組開頭以第j個字母組結尾時候最小劃分的塊數n=strlen(S)/kdp[l][i][j]
Time of Update: 2018-12-04
http://acm.nyist.net/JudgeOnline/problem.php?pid=745此題是連續最大子串和(nyist 44)的變形,只是改成一個環狀而已,由於資料量大,用枚舉起點+加原來的求子串和的代碼是兩重迴圈,必定逾時,但是我還是試了下,下面是有逾時代碼。
Time of Update: 2018-12-04
#include <cstdio>#include <cstring>#include <algorithm>using std::max;const int MAXF = 1000010;const int MAXN = 110;int n;int base[MAXN], len[MAXN], pos[MAXN];char ans;char f[MAXF];char words[MAXN][MAXN];void solve(){ int idx = 0
Time of Update: 2018-12-04
http://acm.nyist.net/JudgeOnline/problem.php?pid=737動態規劃狀態方程:dp[i][j]=d[i][k]+dp[k+1][j]+(sum[k]-sum[i-1])+(sum[j]-sum[k])邊界:0 <=i,j<=n,i<=k<j if(i==j) dp[i][j]=0; sum[i]=前i個數的和。#include <iostream>#include
Time of Update: 2018-12-04
由於它是平面選點,可以將它確定矩形的對角座標x1,y1,x2,y2,,拆成x軸座標x1,y1 和y軸座標x2,y2;然後分別對x軸和y軸區間選點,只要兩個都可以選完,那就說明在它確定的平面上也是可以選出的。需注意輸出時還要還原順序輸出。import java.util.*;class weizhi implements Comparable<weizhi>{int x,y,id;public int compareTo(weizhi A){if(this.y<A.y)
Time of Update: 2018-12-04
Sample Input6 356121920270 0Sample OutputChain 1Depot 1 at restaurant 2 serves restaurants 1 to 3Depot 2 at restaurant 4 serves restaurants 4 to 5Depot 3 at restaurant 6 serves restaurant 6Total distance sum = 8SourceSouthwestern European Regional
Time of Update: 2018-12-04
http://acm.hdu.edu.cn/showproblem.php?pid=1176dp[i][j]:表示第i秒接j位置的餡餅的最大值。三種狀態:dp[i][j]=max(dp[i-1][j],dp[i-1][j-1],dp[i-1][j+1])+a[i][j]分別是上一秒接j位置,上一秒接j-1位置,上一秒接j+1位置。注意數組初始化。#include <iostream>#include <cstring>using namespace std;int dp[
Time of Update: 2018-12-04
dp[i][j]表示從前i個裡選j對,dp[i][j]=min(dp[i-2][j-1]+(a[i]-a[i-1])^2,dp[i-1][j])先排序,注意初始化#include <iostream>#include <algorithm>#include <cmath>#include <cstring> using namespace std;int n,k,m,a[2005],dp[2005][2005];int main(){int
Time of Update: 2018-12-04
char數組:void chen(char a[],char b[])//a=a*b{ int i,j,k,l,sum,c[410]={0}; l=strlen(a)+strlen(b); for(i=strlen(b)-1;i>=0;i--) for(j=strlen(a)-1,k=i+j+1;j>=0;j--,k--) {sum=(b[i]-'0')*(a[j]-'0')+c[k];c[k]=sum%10;c[k-1]+=sum/10;
Time of Update: 2018-12-04
dp[i][j][k]:表示第i次踩踏後兩腳的位置j,k先固定一隻腳的位置j,第i次踩踏後,狀態為dp[i][j][a[i]]或者dp[i][a[i]][j],其中a[i]表示第i個輸入的元素,則有狀態方程:x=dp[i-1][k][j]+cost[k][a[i]]; 是通過k踩過來的,cost[k][a[i]]表示k->a[i]的花費。y=dp[i-1][j][k]+cost[k][a[i]]; 是通過k踩過來的,cost[k][a[i]]表示k->a[i]的花費。dp[i][j]
Time of Update: 2018-12-04
先對火BFS一次,求出每個點的最小著火時間。再對人BFS一次,求出走到邊界的最少時間。#include <iostream>#include <queue>#include <cstring>using namespace std;int n,m,bz[1005][1005],qihuo[1005][1005];char map[1005][1005];int h[4][2]={-1,0,1,0,0,-1,0,1};struct point{int
Time of Update: 2018-12-04
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int a[500005],b[500005]; int i,j,n,an,bn,x,t;int work(int flag){ intans=1; i=j=0; while (i<an&&j<bn) { if (flag) {
Time of Update: 2018-12-04
直接BFS即可。注意兩個資料之間有個空行。#include <iostream>#include <cstring>#include <queue>using namespace std;int n,m,bz[30][30][6][5];char a[30][30];struct point{int x,y,c,se,time;}e;int h[4][2]={-1,0,0,1,1,0,0,-1};queue<point> q;int
Time of Update: 2018-12-04
高精度乘法,字串處理 #include <iostream> #include<iomanip> #include<cstring> using namespace std; int s; void chen(char a[],char b[])//a=a*b { int i,j,k,l,sum,c[410]={0}; l=strlen(a)+strlen(b); for(i=strlen(b)-1;i>=0
Time of Update: 2018-12-04
#define MAXN 1000 // 實際問題時需要修改int mat[MAXN][MAXN]; // 鄰接矩陣mat 的0行0列不用 int nx, ny; // 實際問題時矩陣的行列數 int fy[MAXN], matx[MAXN], maty[MAXN]; int path( int u ) { int v; for (v=1;v<=ny;v++) if (
Time of Update: 2018-12-04
//Uva 10881 #include <iostream>#include <algorithm>#include <cstdio>#define N 10005using namespace std;struct ant{int id,x;int z;//-1向左,0碰撞中,1向右 bool operator <(const ant &a) const{return x<a.x;}}begin[N],end[N];int