Time of Update: 2018-12-05
Binary NumberTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 472 Accepted Submission(s): 313Problem DescriptionFor 2 non-negative integers x and y, f(x, y) is defined as the number of
Time of Update: 2018-12-05
BridgeTime Limit: 2 Seconds Memory Limit: 65536 KB Special Judgen people wish to cross a bridge at night. A group of at most two people may cross at any time, and each group must have a flashlight. Only one flashlight is available among
Time of Update: 2018-12-05
乍一看資料範圍真是有點嚇人,單純暴力肯定逾時。觀察數字可以找到規律:數字範圍 數字位元範圍 每個數字寬度 總共數字所佔位元1~9 : 1~9. 1 4510~99: 11~189 2 9000100~999: 192~2889 3
Time of Update: 2018-12-05
題目實際就是給你兩個數m、n,使得m、n之間的數之和與1~m之間的數之和相等(不包括m)。即:1+2+...+m-1 == (m+1)+...+n; 因此我們可以套用求和公式,兩邊移項化簡得:2*pow(m,2) = n*(n+1)。因此我們可以得到:m =
Time of Update: 2018-12-05
打素數表+快速冪模數。題目較簡單,只要數字滿足其不是素數且利用“Fermat test”方法證明所有情況下均滿足,則其為Carmichael Numbers。注意數字範圍,分治求冪模時要用long long。代碼如下:#include <cstdio>#include <cmath>#include <cstring>bool vis[65002];void Is_Prime(int n)//打素數表{ memset(vis, false,
Time of Update: 2018-12-05
“最大值最小化”問題,先二分求最大值,再貪心實現按最左邊區間最小的格式輸出 。代碼如下:#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<cmath>using namespace std;int main(){#ifdef test freopen("in.txt", "r", stdin);#endif int a[5
Time of Update: 2018-12-05
GCD & LCMTime Limit: 2 Seconds Memory Limit: 65536 KBGiven x and y (2 <= x <= 100,000, 2 <= y <= 1,000,000), you are to count the number of p and q such that:1) p and q are positive integers;2) GCD(p, q) = x;3) LCM(p, q) =
Time of Update: 2018-12-05
分解因子,從9開始分解,一直分解到2。0與1需要特殊處理。代碼如下:#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<cmath>#include<ctime>using namespace std;int main(){#ifdef test freopen("in.txt", "r",
Time of Update: 2018-12-05
可以用完全背包來做,也可以用貪心的方法來做。貪心的話:(1)如果恰好可以湊成t,則更新最大漢堡數(即:A+B最大)。(2)如果湊不成t,則在 t-max最小的情況下,更新A+B的最大值。貪進法(0.024s):#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int _max;int main(){#ifdef
Time of Update: 2018-12-05
純歐拉迴路的題,連通性以及度數,注意 r==0 時特殊情況的處理(此時應該是Not Possible的) ~代碼如下:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>int p[200+5];int find(int x){ return p[x] == x ? x : find(p[x]);}int main(){#ifdef state
Time of Update: 2018-12-05
題還是蠻簡單的,不過因為將main()函數的reture 0寫到了while裡,導致WA了好幾遍,當時老糾結了,怎麼看怎麼對,但就是WA,哎,太粗心了~~~兩次DFS,對骰子進行一次DFS,再對骰子裡面的數字進行一次DFS ~代碼如下:#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<string&
Time of Update: 2018-12-05
算最長路,最長上升子序列的變形。代碼如下:#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int dp[101][101], graph[101][101];int n, r, c;int DP(int i, int j){ if(dp[i][j] > 0) return dp[i][j]
Time of Update: 2018-12-05
是個單調遞減的函數,然後用二分法做,迴圈取估值 ~代碼如下:#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<string>using namespace std;int main(){#ifdef test freopen("sample.txt","r",stdin);#endif
Time of Update: 2018-12-05
一個圖的題,但也可以找規律來做。兩種顏色圖一個圖,要求相鄰兩點顏色不能相同,顯然,以三角形環為例往外推,只要是形成奇數多邊形的環,就不可能實現相鄰兩點的顏色不同,因此只要以每個點為基準,找出所有形成的環,只要存在奇數環就說明不能被塗色,否則就可以~~~代碼如下:#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#inclu
Time of Update: 2018-12-05
回溯,枚舉所有點的黑白情況,然後判斷可行性。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;int map[102][102], node[102], save[101], n, k, cct;int
Time of Update: 2018-12-05
貪心+二分,最大值最小化問題。利用投票箱b的值是一定的,將投票數進行二分,使得算出的投票箱數始終為b。代碼如下:#include<cstdio>int city[500001];int main(){ int n, b; while(scanf("%d%d", &n, &b)) { int Max = 0, l, r, mid; if(n==-1 && b==-1) break;
Time of Update: 2018-12-05
描述:題意就是從1-9之間找出一堆數相乘的積就是輸入的數值,如果沒有,就輸出-1#include <cstdio>#include <cstdlib>int main(){ // freopen("a.txt","r",stdin); int n,x; scanf("%d",&n); while(n--) { scanf("%d",&x); if(x>=10) {
Time of Update: 2018-12-05
題意:判斷一個字串是否能轉化成迴文串,如果可以就統計轉化成迴文串所需的最少交換次數。貪心,思路就是先將串兩端固定(對應字母移至對應位置),依次向中間夾逼,因為只有依次將字母先放到兩端,才可以減少剩下字母交換的次數,先把哪對字母放到兩端都可以,因為可以證明出無論移動哪對字母只要是每次都將其放到兩端其最後交換次數是一樣的。由題意不難判斷如果各個字母出現次數均為偶數,那他一定可以轉換成迴文串,如果有奇數次的字母出現,其有且至多出現一個這樣的字母。如果這個字母出現的次數為一次,我們可以在交換時“忽略”它
Time of Update: 2018-12-05
簡單題,和146 - ID Codes有幾分相似,在此基礎上做就可以了 ~代碼如下:#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<string>using namespace std;int c_cmp(const void *a,const void *b){ return
Time of Update: 2018-12-05
圖題裡最簡單的一個吧 ,DFS~代碼如下:#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<string>using namespace std;char a[100+2][100+2];int flag[100+2][100+2];void DFS(int x,int y){ if(!