原创 C++ String的替換,查找及gets使用 OJ113
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <string> using namespace std; int main() { char te
原创 過橋問題求解
如果給定N個(速度不同)的旅行者,根據結論九我們知道有一個最佳方案,在最初的4步裏用模式一或模式二把最慢的兩個旅行者移動到彼岸,於是問題被約化成N-2個旅行者的形式。問題在於應該選擇哪一種模式。繼續假設A、B爲走得最快和次快的旅行者,
原创 求最大公約數,最小公倍數
設a爲大數,b爲小數 開始後a/b,將b放入a,得到餘數放入b,繼續此過程,餘數爲零時b中即爲最大公約數 最小公倍數爲a*b/最大公約數
原创 求連線數問題 Game of connections
This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, . . . , 2n - 1, 2n consecutively
原创 最少需要數字個數
描述Consider the natural numbers from 1 to N. By associating to each number a sign (+ or -) and calculating the value o
原创 求逆序數
如 5 8 10 | 3 4兩個有序序列,5>3,則8>3,10>3 核心 歸併排序 #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace
原创 C++ ModPow 次方求模
GCC編譯器將__int64轉爲long long即可 int ModPow(__int64 a,__int64 k,__int64 m) { __int64 b=1; while(k>=1) { if(k%2==1)
原创 最大連續子串和
連續查找累加,並連續記錄最大值,當前值,如當前值爲負數則棄掉數據,跳到之後繼續查找 #include <stdio.h> #include <stdlib.h> int main() { int t,ti,n,ni,*num,m
原创 約瑟夫環順序輸出方法及最終值計算
過程輸出 #include<stdio.h> int main() { int n, i, m, p; scanf("%d%d", &n, &m); i = 1; while (i <= n) {
原创 大數相加
#define MaxLen 200 char *BigNumPlus(char *a,char *b) { int i,t; char fa[MaxLen],fb[MaxLen],ret[MaxLen]; int lena=
原创 樹狀數組運用
士兵殺敵(二) 時間限制:1000 ms | 內存限制:65535 KB 難度:5 描述 南將軍手下有N個士兵,分別編號1到N,這些士兵的殺敵數都是已知的。 小工是南將軍手下的軍師,南將軍經常想知道第m號到第n號士兵的總殺敵數,
原创 POJ1611 The Suspects 並查集求解
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 10780 Accepted: 5110 Description Severe
原创 求組合個數 POJ2249 以及一種組合的輸出方法
Description In how many ways can you choose k elements out of n elements, not taking order into account? Write a progra
原创 康託展開及其逆運算
一、康託展開 (1)找出45231在這個排列中的順序 比4小的數有3個比5小的數有4個但4已經在之前出現過了所以是3個比2小的數有1個比3小的數有兩個但2已經在之前出現過了所以是1個比1小的數有0個 二、康託展開的逆運算 (1)找出第
原创 快速輸出指定範圍所有素數
#include<stdio.h> #include<string.h> bool flag[2000000]; int main() { int N; //freopen("E://input.txt","r",stdin)