Topcoder SRM 514div2 500point

來源:互聯網
上載者:User

可以說是一道水題,本以為dfs一下就ok,但是仔細想想,是有規律的,因為題目說可以任意使用,所以,只要jumptype裡面有偶數,就一定yes,為啥呢?因為以2為例,2是可以到達棋盤任何地方的,推廣到其它偶數,他們都可以到達任何地方。另外,當(x+y)為偶數時,也一定yes

#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>using namespace std;class MagicalGirlLevelTwoDivTwo {public:string isReachable(vector <int>, int, int);bool dfs(int s,int t,int x,int y);};string MagicalGirlLevelTwoDivTwo::isReachable(vector <int> v, int x, int y) {    int i,j;    if(!x&&!y)return "YES";    bool even=0;    for(i=0;i<v.size();i++)    if(v[i]%2==0)even=1;    if(even)return "YES";    if((x+y)%2==0)return "YES";    return "NO";}

聯繫我們

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