uva 1595 Symmetry

題目

The figure shown on the left is left-right symmetric as it is possible to fold the sheet of paper along a vertical line, drawn as a dashed line, and to cut the figure into two identical halves. The figure on the right is not left-right symmetric as it is impossible to find such a vertical line.

Paste_Image.png

Write a program that determines whether a figure, drawn with dots, is left-right symmetric or not. The dots are all distinct.

Input

The input consists of T test cases. The number of test cases T is given in the first line of the input file. The first line of each test case contains an integer N, where N (1 ≤ N ≤ 1, 000) is the number of dots in a figure. Each of the following N lines contains the x-coordinate and y-coordinate of a dot. Both x-coordinates and y-coordinates are integers between ?10, 000 and 10, 000, both inclusive.

Output

Print exactly one line for each test case. The line should contain ‘YES’ if the figure is left-right symmetric, and ‘NO’, otherwise.

Sample Input

3
5
-2 5
0 0
6 5
4 0
2 3
4
2 3
0 4
4 0
0 0
4
5 14
6 10
5 10
6 14

Sample Output

YES
NO
YES

分析

給你一堆點(diǎn),讓你看能不能找到一條豎線使所有點(diǎn)左右對(duì)稱(chēng)起趾。思路很簡(jiǎn)單瓣颅,開(kāi)一個(gè)20000的vector存點(diǎn)然后對(duì)每一行找對(duì)稱(chēng)點(diǎn)葬项,看看是不是在一條豎線上,額我寫(xiě)的有點(diǎn)取巧簿寂,其實(shí)是有樣例可以卡掉我的代碼,但是竟然過(guò)了潮饱,蝉衣,括尸,
所以我又寫(xiě)了個(gè)正確的代碼,病毡,

ac代碼

//ac代碼1濒翻,錯(cuò)誤代碼
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
const int maxn = 2e4 + 10;
const int mid = 1e4 + 5;
vector <int> dot[maxn];
int n;
void init(){
    for(int i = 0; i < maxn; ++i){
        dot[i].clear();
    }
    scanf("%d", &n);
    for(int i = 0; i < n; ++i){
        int t1, t2;
        scanf("%d%d", &t1, &t2);
        dot[t2 + mid].push_back(t1);
    }
}
void solve(){
    bool text = 1;
    double t;
    for(int i = 0; i < maxn; ++i){
        if(dot[i].size() == 0) continue;
        double sum = 0;
        for(int j = 0; j < dot[i].size(); ++j){
            sum += dot[i][j];
        }
        sum /= dot[i].size();
        if(text){
            t = sum;
            text = 0;
        }
        else {
            if(t != sum){
                printf("NO\n");
                return;
            }
        }
    }
    printf("YES\n");
}
int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        init();
        solve();
    }
    return 0;
}
//ac代碼2,正確(暫時(shí)沒(méi)發(fā)現(xiàn)什么錯(cuò)誤
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
const int maxn = 2e4 + 10;
const int mid = 1e4 + 5;
vector <int> dot[maxn];
int n;
void init(){
    for(int i = 0; i < maxn; ++i){
        dot[i].clear();
    }
    scanf("%d", &n);
    for(int i = 0; i < n; ++i){
        int t1, t2;
        scanf("%d%d", &t1, &t2);
        dot[t2 + mid].push_back(t1);
    }
}
void solve(){
    bool text = 1;
    double t;
    for(int i = 0; i < maxn; ++i){
        if(dot[i].size() == 0) continue;
        double sum = 0;
        for(int j = 0; j < dot[i].size(); ++j){
            sum += dot[i][j];
        }
        sum /= dot[i].size();
        if(text){
            t = sum;
            text = 0;
        }
        else {
            if(t != sum){
                printf("NO\n");
                return;
            }
        }
    }
    for(int i = 0; i < maxn; ++i){
        for(int j = 0; j < dot[i].size(); ++j){
            if(dot[i][j] == t){
                continue;
            } 
            else{
                int temp = t * 2 - dot[i][j];
                for(int k = 0; ; ++k){
                    if(k == dot[i].size()){
                        printf("NO\n");
                        return;
                    }
                    else if(dot[i][k] == temp) break;
                }
            }
        }
    }
    printf("YES\n");
}
int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        init();
        solve();
    }
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末啦膜,一起剝皮案震驚了整個(gè)濱河市有送,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌僧家,老刑警劉巖娶眷,帶你破解...
    沈念sama閱讀 217,657評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異啸臀,居然都是意外死亡届宠,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門(mén)乘粒,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)豌注,“玉大人,你說(shuō)我怎么就攤上這事灯萍≡” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,057評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵旦棉,是天一觀的道長(zhǎng)齿风。 經(jīng)常有香客問(wèn)我,道長(zhǎng)绑洛,這世上最難降的妖魔是什么救斑? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,509評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮真屯,結(jié)果婚禮上脸候,老公的妹妹穿的比我還像新娘。我一直安慰自己绑蔫,他們只是感情好运沦,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,562評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著配深,像睡著了一般携添。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上篓叶,一...
    開(kāi)封第一講書(shū)人閱讀 51,443評(píng)論 1 302
  • 那天烈掠,我揣著相機(jī)與錄音羞秤,去河邊找鬼。 笑死向叉,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的嗦董。 我是一名探鬼主播母谎,決...
    沈念sama閱讀 40,251評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼京革!你這毒婦竟也來(lái)了奇唤?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,129評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤匹摇,失蹤者是張志新(化名)和其女友劉穎咬扇,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體廊勃,經(jīng)...
    沈念sama閱讀 45,561評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡懈贺,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,779評(píng)論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了坡垫。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片梭灿。...
    茶點(diǎn)故事閱讀 39,902評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖冰悠,靈堂內(nèi)的尸體忽然破棺而出堡妒,到底是詐尸還是另有隱情,我是刑警寧澤溉卓,帶...
    沈念sama閱讀 35,621評(píng)論 5 345
  • 正文 年R本政府宣布皮迟,位于F島的核電站,受9級(jí)特大地震影響桑寨,放射性物質(zhì)發(fā)生泄漏伏尼。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,220評(píng)論 3 328
  • 文/蒙蒙 一尉尾、第九天 我趴在偏房一處隱蔽的房頂上張望烦粒。 院中可真熱鬧,春花似錦代赁、人聲如沸扰她。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,838評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)徒役。三九已至,卻和暖如春窖壕,著一層夾襖步出監(jiān)牢的瞬間忧勿,已是汗流浹背杉女。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,971評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留鸳吸,地道東北人熏挎。 一個(gè)月前我還...
    沈念sama閱讀 48,025評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像晌砾,于是被迫代替她去往敵國(guó)和親坎拐。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,843評(píng)論 2 354

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