• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            worm

            為什么我的眼里飽含淚水?因?yàn)槲页绦驔]寫完!
            隨筆 - 5, 文章 - 2, 評(píng)論 - 10, 引用 - 0
            數(shù)據(jù)加載中……

            2009年3月8日

            poj 3414解題報(bào)告(廣搜題)

                 摘要:                 郁悶?zāi)牵瑢懥似邆€(gè)小時(shí),一直在調(diào)試錯(cuò)誤了!fuck it! 這個(gè)與別的BFS題的主要不同是要記錄正確順序的路徑,我用path[i][j] = {way,a,b}表示狀態(tài)(i,j)是由狀態(tài)(a,b)經(jīng)過方式way(一共六種...  閱讀全文

            posted @ 2009-03-08 18:40 WORM 閱讀(1661) | 評(píng)論 (5)編輯 收藏

            poj 3191解題報(bào)告

            The Moronic Cowmpouter
            Time Limit: 1000MS Memory Limit: 65536K
            Total Submissions: 1344 Accepted: 676

            Description

            Inexperienced in the digital arts, the cows tried to build a calculating engine (yes, it's a cowmpouter) using binary numbers (base 2) but instead built one based on base negative 2! They were quite pleased since numbers expressed in base −2 do not have a sign bit.

            You know number bases have place values that start at 1 (base to the 0 power) and proceed right-to-left to base^1, base^2, and so on. In base −2, the place values are 1, −2, 4, −8, 16, −32, ... (reading from right to left). Thus, counting from 1 goes like this: 1, 110, 111, 100, 101, 11010, 11011, 11000, 11001, and so on.

            Eerily, negative numbers are also represented with 1's and 0's but no sign. Consider counting from −1 downward: 11, 10, 1101, 1100, 1111, and so on.

            Please help the cows convert ordinary decimal integers (range -2,000,000,000..2,000,000,000) to their counterpart representation in base −2.

            Input

            Line 1: A single integer to be converted to base −2

            Output

            Line 1: A single integer with no leading zeroes that is the input integer converted to base −2. The value 0 is expressed as 0, with exactly one 0.

            Sample Input

            -13

            Sample Output

            110111

            Hint

            Explanation of the sample:

            Reading from right-to-left:
            1*1 + 1*-2 + 1*4 + 0*-8 +1*16 + 1*-32 = -13
             題目的意思就是讓你把一個(gè)數(shù)轉(zhuǎn)換為-2進(jìn)制,
            基本原理:
                           如果n為奇數(shù),那么末位肯定為1,因此就可以轉(zhuǎn)為求(x-1)/-2 的子問題了! (除以-2可以類比十進(jìn)制就能理解了)
                           如果n為偶數(shù),末位必為0,然后再轉(zhuǎn)為求x/-2的子問題;
            結(jié)束條件當(dāng) n=1。
            思路很簡(jiǎn)單,但是有兩個(gè)小方面要提提,一定要考慮n=0的情況,我就是沒考慮而一直超時(shí),郁悶,還找不出錯(cuò)誤,陷入了死循環(huán)怪不得超時(shí),還有注意球的結(jié)果是逆序的!!呵呵下面是代碼:
             1//============================================================================
             2// Name        : poj 3191.cpp
             3// Author      : worm
             4// Copyright   : Your copyright notice
             5// Description :把一個(gè)十進(jìn)制的數(shù)轉(zhuǎn)換為-2進(jìn)制的數(shù)
             6//============================================================================
             7
             8#include <iostream>
             9#include <stdio.h>
            10#include <string>
            11#include <math.h>
            12using namespace std;
            13string a= "";
            14int main() {
            15    int x;
            16    cin >> x;
            17    if (x == 0{
            18        cout <<"0"<<endl;
            19        return 0;
            20    }

            21
            22    while (x != 1{
            23        if (abs(x) % 2 == 1{
            24            a += '1';
            25            x = (x-1)/-2;
            26            continue;
            27        }

            28        a += '0';
            29        x /= -2;
            30    }

            31    cout <<"1";
            32    for (int i = a.length() - 1; i >= 0; i--{
            33        printf("%c",a[i]);
            34    }

            35
            36    return 0;
            37}

            38

            posted @ 2009-03-08 12:37 WORM 閱讀(1163) | 評(píng)論 (1)編輯 收藏

            poj 3126 Prim Path 第一道BFS

                  對(duì)于一個(gè)四位數(shù),對(duì)于它某一位變化之后的素?cái)?shù),即“相鄰的素?cái)?shù)”,進(jìn)行廣度搜索,知道搜索到為止!
            挺簡(jiǎn)單,看代碼應(yīng)該可以看懂,下面是代碼
            9#include <iostream>
            10#include <queue>
            11#include <math.h>
            12using namespace std;
            13int a, b;
            14int p[9999= 0 };
            15int visited[9999= 0 };
            16bool isprime(int x) {
            17
            18    for (int i = 2; i <= sqrt((double) x); ++i) {
            19        if (x % i == 0)
            20            return false;
            21    }

            22    return true;
            23}

            24int BFS(int s, int r) {
            25    queue<int> q;
            26    q.push(s);
            27    p[s] = 0;
            28    visited[s] = 1;
            29    while (!q.empty()) {
            30        int temp = q.front();
            31        q.pop();
            32        for (int i = 0; i <= 9; i++{
            33            int y1 = (temp / 10* 10 + i;
            34            if (isprime(y1) && !visited[y1]) {
            35                q.push(y1);
            36                p[y1] = p[temp] + 1;
            37                visited[y1] = 1;
            38            }

            39            int y2 = temp % 10 + (temp / 100* 100 + i * 10;
            40            if (isprime(y2) && !visited[y2]) {
            41                q.push(y2);
            42                p[y2] = p[temp] + 1;
            43                visited[y2] = 1;
            44            }

            45            int y3 = temp % 100 + (temp / 1000* 1000 + 100 * i;
            46            if (isprime(y3) && !visited[y3]) {
            47                q.push(y3);
            48                p[y3] = p[temp] + 1;
            49                visited[y3] = 1;
            50            }

            51            if (i != 0{
            52                int y4 = temp % 1000 + i * 1000;
            53                if (isprime(y4) && !visited[y4]) {
            54                    q.push(y4);
            55                    p[y4] = p[temp] + 1;
            56                    visited[y4] = 1;
            57                }

            58            }

            59            if (visited[r])
            60                return p[r];
            61        }

            62
            63    }

            64    return 0;
            65}

            66int main() {
            67    int n;
            68    cin >> n;
            69    while (n--{
            70        memset(visited,0,sizeof(visited));
            71        memset(p,0,sizeof(p));
            72        cin >> a >> b;
            73        cout << BFS(a, b) << endl;
            74
            75    }

            76    return 0;
            77}

            78

            posted @ 2009-03-08 10:36 WORM 閱讀(1330) | 評(píng)論 (1)編輯 收藏

            2009年3月7日

            第一道廣度搜索BFS紀(jì)念 poj 3278 源代碼

               參考了別人的思路,做出了第一道BFS,雖然在大牛們看來不屑一顧,but about me,I really happy for it, I'm coming ! worm never give up!!
             1//============================================================================
             2// Name        : poj.cpp
             3// Author      :
             4// Version     :
             5// Copyright   : Your copyright notice
             6// Description : Hello World in C++, Ansi-style
             7//============================================================================
             8
             9#include <iostream>
            10#include <queue>
            11using namespace std;
            12queue<int> q;
            13int    result[100001];
            14int visited[100001= {0};
            15int BFS(int start,int end) {
            16    if (start == end)
            17        return 0;
            18    q.push(start);
            19    result[start] = 0;
            20    visited[start] = 1;
            21    while(!q.empty()) {
            22        int temp = q.front();
            23        q.pop();
            24        int next;
            25        for (int i = 0; i < 3++i) {
            26            if (i == 0)
            27                next = temp - 1;
            28            if (i == 1)
            29                next = temp + 1;
            30            if (i == 2)
            31                next = temp*2;
            32            if(next > 100000 || next < 0{
            33                continue;
            34            }

            35            if (visited[next] != 1{
            36                q.push(next);
            37                result[next] = result[temp] + 1;
            38                visited[next] = 1;
            39            }

            40            if (next == end)
            41                return result[next];
            42        }

            43    }

            44    return 0;
            45}

            46int main() {
            47    int n,k;
            48    cin >> n >> k;
            49    cout << BFS(n,k) << endl;
            50    return 0;
            51}

            52

            posted @ 2009-03-07 18:31 WORM 閱讀(1295) | 評(píng)論 (3)編輯 收藏

            2009年3月6日

            poj 3705解題思路及源代碼

             1//============================================================================
             2// Name        : poj.cpp
             3// Author      :
             4// Version     :
             5// Copyright   : Your copyright notice
             6// Description : 題目大意就是將正序數(shù)列1,2,3,,n,通過最少的“復(fù)制粘貼”數(shù)
             7// 變?yōu)槟嫘蛐蛄械膯栴}。
             8//基本思想:  如果n為奇數(shù),假設(shè)n = 7;
             9// 1 2 3 4 5 6 7          將n左邊的最中間的兩個(gè)數(shù)依次移到7的右邊
            10// 1 2 5 6 7 3 4       的最中間
            11// 1 6 7 3 2 5 4
            12// 7 3 2 1 6 5 4          將 3 2 1與 6 5 4 交換
            13// 7 6 5 4 3 2 1
            14//總的次數(shù)為(n+1)/2;
            15// n =  偶數(shù)時(shí),可以先把n不管,這樣n-1就為奇數(shù)的情況,求出后的序列在和n交換一下
            16//即可,結(jié)果為n/2 + 1;
            17//============================================================================
            18
            19#include <iostream>
            20using namespace std;
            21void solve(int n) {
            22    int x = (n+1)/2 - 1;
            23    int y = n;
            24    for (int i = 0; i < x; ++i) {
            25        cout << n/2 << " " << 2 << " " << y-2-<< endl;
            26        n -= 2;
            27    }

            28    cout <<"" << x << " " << x + 1 << endl;
            29}

            30
            31int main() {
            32    int n;
            33    cin >> n;
            34    if (n == 1{
            35        cout << 0 <<endl;
            36        return 0;
            37    }

            38    if (n == 2{
            39        cout << "1" <<endl;
            40        cout << "1 1 1" <<endl;
            41        return 0;
            42    }

            43    if (n % 2 != 0{
            44        cout << (n+1)/2 <<endl;
            45         solve(n);
            46    }

            47    else {
            48        cout << n/2 + 1 << endl;
            49        solve(n-1);
            50        cout << 1 << " "<< n-1 <<" 1" <<endl;
            51    }

            52
            53    return 0;
            54}

            55

            最后一定要注意1 和 2 的情況,我因?yàn)橥丝紤],wa了幾次,呵呵...

            posted @ 2009-03-06 08:52 WORM 閱讀(314) | 評(píng)論 (0)編輯 收藏

            久久精品成人免费观看97| 777米奇久久最新地址| 久久精品人人做人人爽电影| 久久亚洲精品成人无码网站| 伊人久久大香线焦AV综合影院 | 99久久无色码中文字幕| 久久精品国产亚洲网站| 久久久久成人精品无码| 久久久国产打桩机| 久久伊人精品青青草原高清| 久久亚洲精品无码播放| 人妻精品久久久久中文字幕69| 18岁日韩内射颜射午夜久久成人| 人人狠狠综合久久亚洲| 久久人人妻人人爽人人爽| 久久天天躁狠狠躁夜夜不卡| 国产成年无码久久久免费| 97精品伊人久久久大香线蕉| 亚洲人成无码网站久久99热国产| 色妞色综合久久夜夜| 久久99精品久久久久久噜噜| 婷婷久久久亚洲欧洲日产国码AV| 日韩亚洲欧美久久久www综合网| 狠狠色丁香婷婷久久综合五月| 国产精品久久精品| 亚洲国产精品综合久久一线 | 777米奇久久最新地址| 无码任你躁久久久久久| 久久精品国产免费| 少妇熟女久久综合网色欲| 人人狠狠综合久久亚洲88| 亚洲午夜久久久久久噜噜噜| 久久久无码精品午夜| 久久免费小视频| 久久综合久久自在自线精品自| 一级做a爰片久久毛片免费陪| 嫩草影院久久国产精品| 久久精品人人做人人爽97| 久久中文字幕人妻丝袜| 久久影院午夜理论片无码| 国产精品一久久香蕉国产线看观看 |