原创 hdu 1520 (樹形dp)

There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The University has a

原创 HDU 2369 尺取法

Bruce Force’s keyboard is broken, only a few keys are still working. Bruce has figured out he can still type texts

原创 pta 家庭房產

給定每個人的家庭成員和其自己名下的房產,請你統計出每個家庭的人口數、人均房產面積及房產套數。 輸入格式: 輸入第一行給出一個正整數N(≤1000),隨後N行,每行按下列格式給出一個人的房產: 編號 父 母 k 孩子1 … 孩子

原创 CodeForces 676C Vasya and String

High school student Vasya got a string of length n as a birthday present. This string consists of letters ‘a’ and ‘

原创 擴展歐幾里德算法

歐幾里德算法 (輾轉相除法) ll gcd(ll a,ll b) { if(b) return gcd(b,a%b); return a; } 衍生:擴展歐幾里德 原理 : 定義 ax+by=gcd(a,b)

原创 ZOJ 3603 Draw Something Cheat

Have you played Draw Something? It’s currently one of the hottest social drawing games on Apple iOS and Android Dev

原创 HDU 1028 (母函數或者dp)

“The second problem is, given an positive integer N, we define an equation like this: N=a[1]+a[2]+a[3]+…+a[m];

原创 素數 快速冪 gcd.lcm

一 素數 1.判斷一個數是不是素數 如果x<=1 則不是素數 是素數返回true 不是則返回false bool is_pri(ll x) //時間複雜度O(√n) { ll s=sqrt(x+0.5);

原创 SHU A序列 (最大上升子序列)

A序列 描述 如果一個序列有奇數個正整數組成,不妨令此序列爲a1,a2,a3,…,a2∗k+1(0<=k),並且a1,a2…ak+1是一個嚴格遞增的序列,ak+1,ak+2,…,a2∗k+1,是一個嚴格遞減的序列,則稱此序列是A

原创 RMQ 求區間最值

pku 3264 #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <iostream> #include

原创 HDU 3635 Dragon Balls(帶權並查集)

His country has N cities and there are exactly N dragon balls in the world. At first, for the ith dragon ball, the

原创 鏈式前向星

#include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <iostream> #include <map> #inc

原创 hdu 1060 Leftmost Digit

Given a positive integer N, you should output the leftmost digit of N^N. Input The input contains several test ca

原创 HDU 1466 計算直線的交點數

平面上有n條直線,且無三線共點,問這些直線能有多少種不同交點數。 比如,如果n=2,則可能的交點數量爲0(平行)或者1(不平行)。 Input 輸入數據包含多個測試實例,每個測試實例佔一行,每行包含一個正整數n(n<=20)

原创 zoj 3946 Highway Project

Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cit