HDU 3711 Binary Number

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

ZOJ 1877 Bridge

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

UVa 10706 – Number Sequence(POJ 1019)

乍一看資料範圍真是有點嚇人,單純暴力肯定逾時。觀察數字可以找到規律:數字範圍          數字位元範圍    每個數字寬度   總共數字所佔位元1~9 :              1~9.                     1                      4510~99:           11~189                 2                      9000100~999:       192~2889              3

UVa 138 – Street Numbers

題目實際就是給你兩個數m、n,使得m、n之間的數之和與1~m之間的數之和相等(不包括m)。即:1+2+...+m-1 == (m+1)+...+n; 因此我們可以套用求和公式,兩邊移項化簡得:2*pow(m,2) = n*(n+1)。因此我們可以得到:m =

UVa 10006 – Carmichael Numbers

打素數表+快速冪模數。題目較簡單,只要數字滿足其不是素數且利用“Fermat test”方法證明所有情況下均滿足,則其為Carmichael Numbers。注意數字範圍,分治求冪模時要用long long。代碼如下:#include <cstdio>#include <cmath>#include <cstring>bool vis[65002];void Is_Prime(int n)//打素數表{ memset(vis, false,

UVa 714 – Copying Books

“最大值最小化”問題,先二分求最大值,再貪心實現按最左邊區間最小的格式輸出 。代碼如下:#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

ZOJ 1577 – GCD & LCM

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) =

UVa 993 – Product of digits

分解因子,從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",

UVa 10465 – Homer Simpson

可以用完全背包來做,也可以用貪心的方法來做。貪心的話:(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

UVa 10596 – Morning Walk

純歐拉迴路的題,連通性以及度數,注意 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

UVa 657 – The die is cast

題還是蠻簡單的,不過因為將main()函數的reture 0寫到了while裡,導致WA了好幾遍,當時老糾結了,怎麼看怎麼對,但就是WA,哎,太粗心了~~~兩次DFS,對骰子進行一次DFS,再對骰子裡面的數字進行一次DFS ~代碼如下:#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<string&

UVa 10285 – Longest Run on a Snowboard

算最長路,最長上升子序列的變形。代碼如下:#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]

UVa 10341-Solve It

是個單調遞減的函數,然後用二分法做,迴圈取估值 ~代碼如下:#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

UVa 10004 – Bicoloring

一個圖的題,但也可以找規律來做。兩種顏色圖一個圖,要求相鄰兩點顏色不能相同,顯然,以三角形環為例往外推,只要是形成奇數多邊形的環,就不可能實現相鄰兩點的顏色不同,因此只要以每個點為基準,找出所有形成的環,只要存在奇數環就說明不能被塗色,否則就可以~~~代碼如下:#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#inclu

UVa 193 – Graph Coloring

回溯,枚舉所有點的黑白情況,然後判斷可行性。代碼如下:#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

HDU 4190 – Distributing Ballot Boxes

貪心+二分,最大值最小化問題。利用投票箱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;

993 – Product of digits

描述:題意就是從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) {

UVa 10716 – Evil Straw Warts Live

題意:判斷一個字串是否能轉化成迴文串,如果可以就統計轉化成迴文串所需的最少交換次數。貪心,思路就是先將串兩端固定(對應字母移至對應位置),依次向中間夾逼,因為只有依次將字母先放到兩端,才可以減少剩下字母交換的次數,先把哪對字母放到兩端都可以,因為可以證明出無論移動哪對字母只要是每次都將其放到兩端其最後交換次數是一樣的。由題意不難判斷如果各個字母出現次數均為偶數,那他一定可以轉換成迴文串,如果有奇數次的字母出現,其有且至多出現一個這樣的字母。如果這個字母出現的次數為一次,我們可以在交換時“忽略”它

UVa 10098 – Generating Fast

簡單題,和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

UVa 572 – Oil Deposits

圖題裡最簡單的一個吧 ,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(!

總頁數: 61357 1 .... 8685 8686 8687 8688 8689 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.