Time of Update: 2018-12-05
這是我職業生涯的最後一題了。acm留給我的太多太多... 別了。基本的就是用枚舉+貪心。但是有幾個小問題:1.七小對是七個不同的對子。2.東西南北.. 等不能作為順子。考慮這兩點,基本上就沒有trick了。#include<iostream>using namespace std;int cnt[35];int maso[14]={0,8,9,17,18,26,27,28,29,30,31,32,33};int f( char c ){ if( c>='1'
Time of Update: 2018-12-05
brute force是什麼意思?我去.. 暴力的意思... 還以為是禽獸之力呢.. 呵呵#include<stdio.h>int ans[111111];int main(){ int a,b,n; scanf( "%d %d %d",&a,&b,&n ); ans[0]=a; a%=b; bool found; for( int i=1;i<=n;i++ ) { found=false;
Time of Update: 2018-12-05
所有題在A不掉之前都是難題,而當你把它A掉後,它便成了水題,而在你A掉它之前,你永遠不知道它有多水。這道題,我最先想到的是DP,覺得就是一個典型背包問題,不過是背包多了一點而已,然而再仔細一想N=50便意味著50個背包,128^50的運算量,不用細算也知道這樣的程式跑出來太陽都熄火了,所以這樣的DP是走不通的。想到這個section的主題是講搜尋最佳化的,那就試試搜尋吧,直接DFS加剪枝?嗯,想了很久沒想出來怎麼做DFS,就在這個時候ZZY看完了剛更新的日劇,坐在旁邊搖頭晃腦滿臉的意猶未盡,時不
Time of Update: 2018-12-05
這是一道DP問題,個人覺得挺有意思的,呵呵……!首先定義了一個dp[21][21][21]的三維數組。dp[i][j][k]表示使用到了i張唱片,已燒錄到了第j首歌,且當前正在燒錄的唱片已佔用了時間為k時的最優解。狀態轉移方程為:dp[i][j][k] = max{dp[i][j-1][k-data[j]]+1,dp[i][j-1][k],dp[i-1][j-1][kk]}其中1<=kk<=k.代碼好下:/*ID: guo geerPROG: rockersLANG:
Time of Update: 2018-12-05
這... 練練搜尋吧... 自己寫的雜湊都不行.. 悲催悲催.../********************HDU 4277Sevenster2012.09.12********************/#include<iostream>#include<algorithm>#include<set>#include<cmath>#define HashSize (1<<15)-1;using namespace std;int T,
Time of Update: 2018-12-05
題意:a^p=a%p;則稱p為以a為基的素數。給定p與a,求判斷在p不為素數的情況下,a^p=a%p是否成立。#include<iostream>#define ll long longusing namespace std;ll mul( ll a,ll b,ll mod ){ ll ret=0; while( b>0 ) { if( b&1 ) ret=(ret+a)%mod; b>>=1;
Time of Update: 2018-12-05
終於切掉了我的第一道最小費用流了...#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<queue>#include<algorithm>#define MN 222using namespace std;struct Home{ int i,j; }H[MN];struct
Time of Update: 2018-12-05
這道題目很意思,呵呵……代碼好下:/*ID: guo geerPROG: fenceLANG: C++*/#include<iostream>#include<cstring>#include<cmath>#include<fstream>using namespace std;int a[510][510],b[510],path[1029],stack[1029];int getMin(int s[]){ for(int i=1;
Time of Update: 2018-12-05
題目大意:從起點1到終點N的一個圈,最小路徑花費。完畢。構圖跑兩次spfa,完畢。#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<queue>#include<cmath>#include<algorithm>#define NN 1111#define MN 11111using namespace
Time of Update: 2018-12-05
好久沒寫過題目了……呵呵!這是一道DP問題,比較簡單!代碼如下:/*ID: guo geerPROG: game1LANG: C++*/#include<iostream>#include<fstream>#include<cstring>#include<string>using namespace std;int dp[210][210];int data[210];int s[210];int main(){ ifstream fin(
Time of Update: 2018-12-05
這是一道簡單的DP問題。代碼好下:/*ID: guo geerPROG: rangeLANG: C++*/#include<iostream>#include<fstream>#include<cstring>#include<cmath>using namespace std;char data[300][300];int dp[300][300];int res[300];int main(){ ifstream
Time of Update: 2018-12-05
第一次在ubuntu下寫程式,鼓搗了N久終於可以寫東西了.從安裝作業系統,編譯軟體,編譯環境...感覺自己弱成渣渣了... 一道水題 調了N久...各種悲催..#include<cstdio>#include<cstdlib>#include<algorithm>#include<cstring>#include<cmath>using namespace std;struct Point2D{ double x,y; }mesh[33
Time of Update: 2018-12-05
這道題想了許久,沒有思路,後來參考了網上大牛們的做法!——竟然是一道DP問題。可歎自己壓根就沒往這方面想。第一次寫5維DP問題。自己重頭看了一遍01背包問題,這才有所領悟。覺得這道題目有兩點很關鍵:一、輸入資料存放區及處理;二、5維DP問題的理解;/*ID: guo geerPROG: shoppingLANG: C++*/#include<iostream>#include<cstdio>#include<cstring>using namespace
Time of Update: 2018-12-05
這道題比較簡單。不過還是得注意考慮幾種特殊情況,如下所示:還有就是得去掉相交的點即可。代碼如下:/*ID: guo geerPROG: fence9LANG: C++*/#include<iostream>#include<fstream>#include<cstdio>#include<cstring>#include<string>#include<cmath>using namespace std;int main()
Time of Update: 2018-12-05
剛做素數部分,把以前不懂的題目搞定了。還不錯。#include<iostream>#define N 50001using namespace std;bool f[N],seg[1111111];int prime[N],pcnt;__int64 rec[1111111];void deal( __int64 L,__int64 U ){ memset( seg,true,sizeof(seg) ); for( int i=1;i<=pcnt;i++ ) {
Time of Update: 2018-12-05
這道題可以用來練習編碼!代碼如下:/*ID: guo geerPROG: heritageLANG: C++*/#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<fstream>using namespace std;struct Node{ char v; Node *left; Node
Time of Update: 2018-12-05
定義:如果m是一個正整數,且2^m-1是一個素數,則m必是素數.反之,如果m是一個正整數,素數且Mm=2^m-1成為第m個梅森數;如果p是一個素數,並且Mp=2^p-1也是素數,那麼Mp=2^p-1也是素數,那麼Mp就稱為梅森素數.Lucas-Lehmer判定方法.設p是素數,第p個梅森數為Mp=2^p-1,r1=4;對於k>=2,利用rk=((r(k-1))^2-1)%Mp,0<=rk<Mp可以得到rk的序列,則有Mp是素數,若且唯若rp-1%Mp==0;#include&l
Time of Update: 2018-12-05
這是USACO的一篇關於計算幾何的文章,個人覺得挺好的。連結為:http://ace.delos.com/usacotext2?a=5xaW13je5sS&S=geom Computational GeometryPrerequisitesGraph TheoryShortest PathToolsThis module discusses several algorithms that calculate various geometric properties, mostly
Time of Update: 2018-12-05
本來這道題目卻被不想寫的,因為方法有點麻煩。不過最後還是耐下性子寫了。嗚……思路是挺簡單的。設觀察位置為A,BC為多邊形上的一條邊。若有邊擋住了A點的視線,剛更新A當前的視野。如:此時視野為BC1此時視野為B1C此時被完全擋住,沒有視野。代碼如下:/*ID: guo geerPROG: fence4LANG:
Time of Update: 2018-12-05
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactlyk cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph verticesa, b andc, such that