原创 HDU1004:Let the Balloon Rise

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1004/* 簡單題,統計氣球數最多的顏色 */ #include <stdio.h> #define SIZE_ROW 1001 #defin

原创 HDU1000:A+B

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1000這題不用說了吧,加法#include <stdio.h> int main() { int a, b;

原创 1003:Hangover

題目鏈接:http://poj.org/problem?id=1003 求1/2+1/3+....+1/n達到給定的值所需要的最少的項數。 #include <stdio.h> #include <stdlib.h> int main(

原创 HDU1091:A+B for Input-Output Practice (III)

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1091/* 與1000的區別是,0 0中止輸入 */ #include <stdio.h> int main() { int a, b;

原创 HDU1093:A+B for Input-Output Practice (V)

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1093/* 與HDU1092的區別是多了個輸入數據組數。 */ #include <stdio.h> int main() { int

原创 HDU1096:A+B for Input-Output Practice (VIII)

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1096/* 與1093的區別是每行結果後多個空行,最後行輸入後沒有空行 */ #include <stdio.h> int main()

原创 HDU1095:A+B for Input-Output Practice (VII)

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1095/* 與1000的區別是每行輸出間多個空行 */ #include<stdio.h> int main() { int a, b;

原创 HDU1001:Sum Problem

/* Sn = n*(n+1)/2 把兩個相同的自然數列逆序相加 2Sn=1+n + 2+(n-1) + 3+(n-2) + ... n+1 =n+1 +n+1 + ... +n+1 =n*(n+1) Sn=n*(n+1)/2 另, m到

原创 HDU1092:A+B for Input-Output Practice (IV)

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1092/* 每行第一個數爲需要相加的數據個數,第一個數爲0則退出輸入 */ #include <stdio.h> int main() {

原创 HDU1003:Max Sum

/* 設a[i]爲和最大序列的起點,則如果a[i]是負的,那麼它不可能代表最優序列的起點,因爲任何包含a[i]作爲起點的子序列都可以通過a[i+1]作起點而得到改進。 類似的,任何負的子序列也不可能是最優子序列的前綴。 注意:如果全爲負值

原创 HDU1090:A+B for Input-Output Practice (II)

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1090/* 類似HDU1000,多了輸入數據的組數。 */ #include <stdio.h> int main() { int N;

原创 參加ACM比賽所需的基礎知識

一、語言是最重要的基本功        無論側重於什麼方面,只要是通過計算機程序去最終實現的競賽,語言都是大家要過 的第一道關。亞洲賽區的比賽支持的語言包括C/C++與JAVA。筆者首先說說JAVA,衆所 周知,作爲面向對象的王牌語言,J

原创 快速求冪

舉個例子:2^7=2^(4+2+1)=(2^4)*(2^2)*(2^1); 而7的二進制表示方法爲111。 也就是只有在二進制數位上爲1時乘一個2^n,而在二進制數位上爲0時,則不乘。 int pow3(int x, int n) {

原创 01揹包問題

題目     有N件物品和一個容量爲V的揹包。第i件物品的費用是c[i],價值是w[i]。求解將哪些物品裝入揹包可使這些物品的費用總和不超過揹包容量,且價值總和最大。   基本思路     這是最基礎的揹包問題,特點是:每種物品僅有一件

原创 歐幾里得算法

gcd = greatest common divisor 歐幾里德算法又稱輾轉相除法,用於計算兩個整數a,b的最大公約數。其計算原理依賴於下面的定理: 定理:gcd(a,b) = gcd(b,a mod b) 證明:a可以表示成a =