原创 HNU 12844 Arrangement of Contest

#include<bits/stdc++.h> using namespace std; int a[50]; int main() { char s[50]; int n; while(scanf("%d",&n

原创 Codeforces 361A Levko and Table

在n*n矩陣的對角線上輸出k即可 #include<bits/stdc++.h> using namespace std; int main() { int n,k; scanf("%d%d",&n,&k); f

原创 HNU 12850 Garage

長爲H的格子裏面放n個長爲h的格子 最多會有n+1個空隙 要使每個空隙長度都小於h (H-h*n)/(n+1)<h n>(H/h-1)/2 #include<bits/stdc++.h> int main() { int W,H,

原创 Codeforces 279B Books

#include<bits/stdc++.h> using namespace std; int a[100020]; int main() { int n,t; scanf("%d%d",&n,&t); int

原创 POJ 2503 Babelfish

map解法 #include<bits/stdc++.h> using namespace std; map<string,string>p; int main() { string a,b; while(cin>>a)

原创 HDU 4908 BestCoder Sequence

將大於M的數標記爲1 小於M的數標記爲-1 M本身標記爲0  則題目就是要求和爲0並且包括M的連續序列的個數 用sum[i]表示從第1個數大牌第i個數的標記的和 對於所有大於等於M的位置的i 我們要求小於M的位置的sum[j]==sum[

原创 HDU 4858 項目管理

BestCoder Round #1 數據不大 #include<bits.stdc++.h> using namespace std; vector<int>vec[100020]; int f[100020]; int main()

原创 POJ 3311 Hie with the Pie (狀壓DP)

狀態壓縮DP dp[i][j]表示在i狀態(用二進制表示城市有沒有經過)時最後到達j城市的最小時間 轉移方程dp[i][j]=min(dp[i][k]+d[k][j],dp[i][j])   d[k][j]是k城市到j城市的最短距離 要先

原创 HDU 4907 Task schedule

對於詢問q 如果q不存在直接輸出q 否則輸出後面第一個不存在的數 從2*10^5到1遍歷一邊ac #include<bits/stdc++.h> using namespace std; int a[200020],b[200020];

原创 NEU 1440 The minimum square sum (平方剩餘和歐拉準則)

若p=2或p=4*k+1 則p可以表成兩平方數的和的形式 (歐拉和費馬已證明,並且有求的方法) 所以答案是p 若p=4*k+3 設a^2=n(mod p) (n!=0)  可以證明不存在b,b^2=p-n(mod p) 即若n是p的平方剩

原创 HNU 12845 Ballot Analyzing Device

#include<bits/stdc++.h> using namespace std; struct vote{ int x; string s; }v[20]; bool cmp(vote a,vote b) {

原创 HiHo 1032 最長迴文子串 (Manacher算法求解)

Manacher算法o(n)求解最長迴文子串問題 非常巧妙 #include<bits/stdc++.h> using namespace std; char str[2000020],s[2000020]; int p[2000020

原创 HDU 4883 TIANKENG’s restaurant

建立數組遍歷求最大值即可 #include<bits/stdc++.h> using namespace std; int t[2020]; int main() { int T,n,a; char s1[10],s2[1

原创 HNU 12848 Energy Tycoon (貪心)

貪心 #include<bits/stdc++.h> using namespace std; int main() { long long n; char s[100020]; while(scanf("%I64

原创 Codeforces 363A Soroban

算盤的模擬 #include<bits/stdc++.h> using namespace std; int main() { char s[20]; scanf("%s",&s); int len=strlen(