Time of Update: 2018-12-03
看了遞推的題解,感覺遞迴在這個時候有不少優勢了,雖然時間的差距還是有點思路:對於每次搜尋到某個位置的時候,可能有兩個狀態,大寫開,大寫關,記錄下到達某個位置的兩個狀態的最優解。注意大寫開的,最後還得+1,把它關了。#include<stdio.h>#include<string.h>int visited[105][3];char s[105];int dfs(int ,int );int sl;int main(){int
Time of Update: 2018-12-03
求最大產生樹中權值最小的邊,構造樹的時候要注意只要1和n通了就可以結束了,也就是說可能不用構造出完整的n-1條邊。#include <stdio.h>#include <string.h>#include <stdlib.h>typedef struct tEdge{int x;int y;int w;}Edge;Edge e[500000];int n,m;int set[1001];int cmp(const void* x,const
Time of Update: 2018-12-03
題意是給一堆DNA序列,根據各個DNA序列的逆序數排序。這題稍微特殊點,序列的構成元素只有ACGT,因此看到discuss裡有人說是可以O(n)求逆序數的(通過統計ACGT的個數),但是我因為想練練歸併的方法,所以用的歸併,複雜度當然是O(nlgn)了,好在也16ms過了。
Time of Update: 2018-12-03
題目羅嗦了一大堆,其實就是個算術題......#include <stdio.h>#include <string.h>int day;char month[10];int year;int days;char* haab_months[]={"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin",
Time of Update: 2018-12-03
#include<stdio.h>#include<string.h>#define INF 1<<29int dp[32768][15];//第一維目前狀態 第二維為現在所在位置 int start[32768][15];int bit_mask[30];int map[16][16];int main(){int n,i,j,k,newi,begin,min;bit_mask[0]=1;for(i=1;i<30;i++)bit_mask[i]
Time of Update: 2018-12-03
在editplus中的自訂Tool裡面使用lua編譯器來做lua語法檢查的時候, 出錯的輸出會輸出到Output視窗,如果沒有設定 output pattern的話, 雙擊錯誤資訊是不會自動跳轉到出錯行的。output pattern是使用Regex來匹配lua編譯器的輸出的,在網上找了好久也沒找到這個Regex。實在無奈只好研究了下Regex的文法, 自己寫了一個。 獻給大家。在建立User Tool的時候有個按鈕Ouput Pattern(在Capture Output那個複選框右邊).
Time of Update: 2018-12-03
教科書上直接就能搬過來的演算法.......對於已經修好的路(必選邊)可以將其權設為0,這樣這幾條邊就會被優先選到了。判斷迴路可以用並查集做,用簡單的數組實現就可以了。邊最好按照權值排個序吧,或者弄個最小堆,我實在是太懶了,就沒有弄這塊,直接遍曆找的最小.....#include <stdio.h>int road[100][100];int N;int set[100];int get_min_road(int* min_i,int* min_j){ int
Time of Update: 2018-12-03
題目挺嚇人的,2*5會多個0啊,10會多個0啊,25*4會多倆0啊,這樣想就挺亂的....直接上結論了,可以將N!做個質因子分解,裡邊肯定有5^x這一項,目標就是求x的值。也就是說有多少個5,就有多少個0 。然後我一開始就從1到N遍曆開始用5除了,然後逾時了。後來又想想發現直接除5、除5^2,除5^3等等就可以了,代碼超短.....#include <stdio.h>int cal(int num){int sum=0;int i;for(i=5;i<=num;
Time of Update: 2018-12-03
首碼次數總和=首碼種類數+每種首碼在後面的出現次數貼一個不錯的題解,但是題解有個地方講的不是太清晰,就是為什麼next【j】+1==next【j+1】的時候就不統計了呢?http://972169909-qq-com.iteye.com/blog/1114968因為如果next等於後一個next值加一的話,這次的統計會在後面也被統計到,所以忽略#include<stdio.h>#include<string.h>#define val 200005int
Time of Update: 2018-12-03
這題關鍵是要能看出是讓求最小產生樹來.....程式拿2253的改改就能過了....#include <stdio.h>#include <stdlib.h>typedef struct tEdge{int x;int y;int w;}Edge;Edge e[2000000];char str[2000][8];int n,ei;int set[2000];int cmp(const void* x,const void* y){return
Time of Update: 2018-12-03
#include <stdio.h>#include <string.h>int N;int c[28][28];int set[28];int prim(void){set[0]=1;int i,j,min,mi,mj;int count=N-1;int result=0;while(count--){min=10000;for(i=0;i<N;i++){for(j=i+1;j<N;j++){if(set[i]+set[j]==1&&c[i]
Time of Update: 2018-12-03
並查集判斷一下是不是連通圖,然後數組統計一下頂點的入度資訊就好了,只有一個節點入度為0,其他所有的入度為1。很極品的是空樹0 0這組資料,結果應該是“是”。#include <stdio.h>#include <string.h>int indegree[100];int treenode[100];int nc;int occ[100];int set[100];int find(int i){int
Time of Update: 2018-12-03
直接想的話不太容易想到,但是看到思路後,又會發現其實不是那麼難理解,就像捅破一張紙......#include <stdio.h>#include <string.h>void getNext(char* t,int* next){int length=strlen(t);int k=-1;int j=0;next[0]=-1;while(j<length){if(k==-1||t[k]==t[j]){k++;j++;next[j]=k;}else{
Time of Update: 2018-12-03
最基本的題了,一直合并合并。。。最後數數集合的數量就好了。#include <stdio.h>int n,m;int set[50001];int occ[50001];int find(int i){int j=i;while(i!=set[i]){i=set[i];}set[j]=i;return i;}void union_set(int i,int j){i=find(i);j=find(j);set[i]=j;}int main(void){int i,x,
Time of Update: 2018-12-03
很有意思的一道題,一看感覺無從下手,後來一想,其實把匹配串複製一遍,然後用KMP搜一遍就行了、#include<stdio.h>#include<string.h>#include<cstring>#define val 100005int lens,lenp,next[val];char s[val*2],p[val];bool kmp();int
Time of Update: 2018-12-03
#include<stdio.h>#include<stdlib.h>#define Max 100typedef struct btree{int data;struct btree *left;struct btree *right;}tree;typedef struct Queue{int tail,head;tree * a[Max];}queue;void create(queue &);void enqueue(int
Time of Update: 2018-12-03
先排序,然後貪心選..........雖然不會證為什麼貪心可以.......#include <stdio.h>#include <stdlib.h>typedef struct tStick{int l;int w;}Stick;int n;Stick s[5000];int used[5000];int cmp(const void* x1,const void* y1){Stick* x=(Stick*)x1;Stick* y=(Stick*)y1;
Time of Update: 2018-12-03
這道題一直在糾結,,整整一天了,,,,,,,剛開始一直不知道如何建圖,,糾結了好久,,,看了討論區,,終於明白了如何建圖,,接下來就是wr了,,wr了好久,,,,最後發現是一個小bug,,氣的要死,,,,,,,一道不錯的題,,題目:Muddy FieldsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5134 Accepted: 1901DescriptionRain has pummeled the
Time of Update: 2018-12-03
好像編譯原理裡邊東西的簡化版,只有一個產生式S->CSS|DSS|ESS|ISS|NS|p-z(CDEIN都是終結符),一個不是很麻煩的遞迴.......#include <stdio.h>#include <string.h>char str[257];char* legal(char* str){//str開頭的字串是否合法,如果合法,返回合法語句的下一個位置char
Time of Update: 2018-12-03
給個字母矩陣,從左上方開始走,同樣的字母不能經過兩次,求最長走多少步。好像直接搜就好了,比較水........#include <stdio.h>int R,C;int v[26];char ch[20][21];int directions[4][2]={{0,1},{0,-1},{1,0},{-1,0}};int dfs(int r,int c){v[(int)(ch[r][c]-'A')]=1;int i,nr,nc,t,vi;int mt=0;for(i=0;