【UVa10167】 Birthday Cake,思路+代碼+解題報告

來源:互聯網
上載者:User
#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>// #define INPUT/**    Problem: UVA10167 - Birthday Cake    Begin Time:22nd/Mar/2012 5:00 p.m.    End Time: 22nd/Mar/2012 7:35 p.m.    Last Time: 2H 35M    Thought:        就是根據題目中給的條件搜尋        1.A,B∈[-500,500]        2.至少有一個解,輸出其中之一就可以了    Experience:        這麼簡單的一道題,竟然WA了10次+,究其原因,就是審題不細 + 搜尋功底不行        1.由於審題不細,有2n lines follow沒看到,導致輸入的時候只輸入了N行,WAWAWA        2.由於審題不細,沒看到給出了答案的範圍,從而想得有些複雜,WAWAWA        3.搜尋的時候一定要注意!!先搜尋再判斷解,在這道題裡是這樣的        如果你把判斷解先放在前面,那麼可能搜尋到了下一個狀態,但是你的解停留在        上一個狀態,這時候你輸出的i,j是現在的狀態而不是上一個狀態,導致WA,這個        問題是WA的最多次的,日日日。    Knowledge Point:    單純的搜尋,甚至歸類不能歸成BFS/DFS。*/using namespace std;const int MAX_CHERRY = 110000;struct node{    int x;    int y;};node cherry[MAX_CHERRY];void Solve(const int num){    int moreThan = 0;    int lessThan = 0;    for(int i = -500 ; i <= 500 ; i++)    {        for(int j = -500 ; j <= 500 ; j++)        {            moreThan = 0; lessThan = 0;            for(int k = 0 ; k < num ; k++)            {                if(cherry[k].x * i + cherry[k].y * j > 0)                {                    moreThan++;                }                if(cherry[k].x * i + cherry[k].y * j < 0 )                {                    lessThan++;                }                if(cherry[k].x * i + cherry[k].y * j == 0)                {                    break;                }                if(moreThan == lessThan && moreThan + lessThan == num)                {                    printf("%d %d\n",i,j);                    return;                }            }        }    }}int main(){#ifdef INPUT    freopen("b:\\acm\\uva\\UVA10167\\input.txt","r",stdin);#endif    int n;    int x,y,num;    while (scanf("%d",&n) != EOF )    {        if ( n == 0 ) break;        x = 0 ; y = 0 ; num = 0;        for(int i = 0 ; i < 2 * n ; i++)        {            scanf("%d %d",&cherry[i].x,&cherry[i].y);        }        Solve(2*n);    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.