POJ 1244 Slots of Fun

POJ 1244 Slots of Fun

The International Betting Machine company has just issued a new type of slot machine. The machine display consists of a set of identical circles placed in a triangular shape. An example with four rows is shown below. When the player pulls the lever, the machine places a random letter in the center of each circle. The machine pays off whenever any set of identical letters form the vertices of an equilateral triangle. In the example below, the letters 'a' and 'c' satisfy this condition.

樣例圖片

In order to prevent too many payoffs, the electronics in the machine ensures that no more than 3 of any letter will appear in any display configuration.
IBM is manufacturing several models of this machine, with varying number of rows in the display, and they are having trouble writing code to identify winning configurations. Your job is to write that code.

Input

Input will consist of multiple problem instances. Each instance will start with an integer n indicating the number of rows in the display. The next line will contain n(n + 1)/2 letters of the alphabet (all lowercase) which are to be stored in the display row-wise, starting from the top. For example, the display above would be specified as
4
abccddadca
The value of n will be between 1 and 12, inclusive. A line with a single 0 will terminate input.

Output   

For each problem instance, output all letters which form equilateral triangles on a single line, in alphabetical order. If no such letters exist, output "LOOOOOOOOSER!".

Sample Input

4
abccddadca
6
azdefccrhijrrmznzocpq
2
abc
0

Sample Output

ac
crz
LOOOOOOOOSER!

題目的大意就是要判斷輸入中字母相同且構(gòu)成等邊三角形三點的字母有哪些,
等邊三角形等邊三角形统倒,就是三邊相等就行了蜕径,數(shù)據(jù)也小,直接暴力就行启盛,最主要的問題是求兩點間的距離,這里可以把整個三角形就是一個60°的斜坐標(biāo)系,推一下斜坐標(biāo)系兩點距離就可以了


坐標(biāo)系.png

\ |\vec{ab}|=|\vec{a}-\vec液斜|=\sqrt{( (x_1-x2_1)\vec{e_1}+(y_1-y2_1)\vec{e_2})^2}
\quad\quad =\sqrt{(x_1-x_2)^2+(y_1-y_2)^2-(x_1-x_2)(y_1-y_2)}

然后到這里就把ab的距離求出來了求类,直接暴力判斷三點距離相等就行了

#include<iostream>
#include<cstring>
using namespace std;
char record[13][13];
int zmnum[26];
int zm[26][4][2];
int result[26];
int getdis(int x1,int x2,int y1,int y2){
    return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)-(x2-x1)*(y2-y1);
}
int main(){
    int n;
    while(cin>>n&&n){
        memset(result,0,sizeof(result));
        memset(zm,0,sizeof(zm));
        memset(zmnum,0,sizeof(zmnum));
        for(int i=0;i<n;i++){
            for(int j=0;j<=i;j++){
                cin>>record[i][j];
            }
        }
        if(n==1){
            cout<<"LOOOOOOOOSER!"<<endl;
            continue;
        }
        double layer=((n+1)*n)/2;
         for(int i=0;i<n;i++){
            for(int j=0;j<=i;j++){
                char c=record[i][j];
                zm[c-'a'][zmnum[c-'a']][0]=i;
                zm[c-'a'][zmnum[c-'a']++][1]=j;
            }
        }
        bool loser=true;
        for(int i=0;i<26;i++){
            char c=i+'a';
            if(zmnum[i]<3)continue;
            int l1=getdis(zm[i][0][0],zm[i][1][0],zm[i][0][1],zm[i][1][1]);
            int l2=getdis(zm[i][1][0],zm[i][2][0],zm[i][1][1],zm[i][2][1]);
            int l3=getdis(zm[i][2][0],zm[i][0][0],zm[i][2][1],zm[i][0][1]);
            if(l1==l2&&l2==l3)loser=false,cout<<c;
        }
        if(loser)cout<<"LOOOOOOOOSER!";
        cout<<endl;
    }
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末奔垦,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子尸疆,更是在濱河造成了極大的恐慌椿猎,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,826評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件寿弱,死亡現(xiàn)場離奇詭異犯眠,居然都是意外死亡,警方通過查閱死者的電腦和手機症革,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,968評論 3 395
  • 文/潘曉璐 我一進店門筐咧,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事量蕊∑贪眨” “怎么了?”我有些...
    開封第一講書人閱讀 164,234評論 0 354
  • 文/不壞的土叔 我叫張陵残炮,是天一觀的道長韭赘。 經(jīng)常有香客問我,道長势就,這世上最難降的妖魔是什么泉瞻? 我笑而不...
    開封第一講書人閱讀 58,562評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮蛋勺,結(jié)果婚禮上瓦灶,老公的妹妹穿的比我還像新娘。我一直安慰自己抱完,他們只是感情好贼陶,可當(dāng)我...
    茶點故事閱讀 67,611評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著巧娱,像睡著了一般碉怔。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上禁添,一...
    開封第一講書人閱讀 51,482評論 1 302
  • 那天撮胧,我揣著相機與錄音,去河邊找鬼老翘。 笑死芹啥,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的铺峭。 我是一名探鬼主播墓怀,決...
    沈念sama閱讀 40,271評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼卫键!你這毒婦竟也來了傀履?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,166評論 0 276
  • 序言:老撾萬榮一對情侶失蹤莉炉,失蹤者是張志新(化名)和其女友劉穎钓账,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體絮宁,經(jīng)...
    沈念sama閱讀 45,608評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡梆暮,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,814評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了羞福。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片惕蹄。...
    茶點故事閱讀 39,926評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖治专,靈堂內(nèi)的尸體忽然破棺而出卖陵,到底是詐尸還是另有隱情,我是刑警寧澤张峰,帶...
    沈念sama閱讀 35,644評論 5 346
  • 正文 年R本政府宣布泪蔫,位于F島的核電站,受9級特大地震影響喘批,放射性物質(zhì)發(fā)生泄漏撩荣。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,249評論 3 329
  • 文/蒙蒙 一饶深、第九天 我趴在偏房一處隱蔽的房頂上張望餐曹。 院中可真熱鬧,春花似錦敌厘、人聲如沸台猴。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,866評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽饱狂。三九已至,卻和暖如春宪彩,著一層夾襖步出監(jiān)牢的瞬間休讳,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,991評論 1 269
  • 我被黑心中介騙來泰國打工尿孔, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留俊柔,地道東北人。 一個月前我還...
    沈念sama閱讀 48,063評論 3 370
  • 正文 我出身青樓活合,卻偏偏與公主長得像雏婶,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子芜辕,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,871評論 2 354

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,331評論 0 10
  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,497評論 0 23
  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    網(wǎng)事_79a3閱讀 12,068評論 3 20
  • 這兩天尚骄,我們一群人來湖南考心理咨詢師,昨天上午剛考試結(jié)束侵续。我們最初8個人一起的倔丈,現(xiàn)在只剩下我們?nèi)齻€人在長沙玩了。 ...
    愛笑的女孩運氣好閱讀 231評論 0 1
  • 兒子十歲了状蜗,前天剛過的生日需五,他很高興又激動,導(dǎo)致頭天晚上晚睡著一個多小時轧坎,為什么會這么激動呢宏邮,我是沒有這樣的體驗,...
    屰月閱讀 339評論 1 4