HDU 1495-very Cola/swun 1307-a bucket of gasoline

Source: Internet
Author: User

 

Swun question address:

Http: // 218.194.91.48/acmhome/problemdetail. do? & Method = showdetail & id = 1307

HDU question address: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1495

 

At first glance, it was quite difficult. In fact, it was the basic BFs, a trainer... I found a rule and wrote a-B-lengthCode~~

 

The Code should be well understood ~~

 

 

# Include <iostream> # include <cstring> using namespace STD; struct node {int S, N, M, T; node () {} node (int A, int B, int C, int d) {S = A, n = B, M = C, T = D;} que [400000]; bool vis [104] [104]; inline int add (int A, int R, int R) {return a + r <= r? A: r-r;} int BFS (int s, int N, int m) {If (S & 1) Return-1; int p, q, n, m, s, T; memset (VIS, 0, sizeof (VIS); que [p = q = 0] = node (S, 0, 0 ); while (P <= q) {n = que [p]. n, m = que [p]. m, S = que [p]. s, T = que [p]. t; P ++, t ++; If (vis [s] [N]) continue; vis [s] [N] = true; if (n = 0 & M = S | M = 0 & n = s) return T-1; que [+ q] = node (S-add (S, N, N), N + Add (S, N, N), M, t ); que [++ q] = node (S, N + Add (m, n, n), M-add (m, n, n), t ); que [++ q] = node (S, N-add (n, m, m), m + Add (n, m, m), t ); que [++ q] = node (S-add (S, M, m), n, m + Add (S, M, m), t ); que [++ q] = node (S + N, 0, M, T); que [++ q] = node (S + m, n, 0, t);} return-1;} int main () {int S, N, M, Res; while (CIN> S> N> M, S) {res = BFS (S, n, m); If (RES =-1) cout <"no" <Endl; else cout <res <Endl ;} return 0 ;}

 

This is written according to the regular expression of the table ~~

 

 
# Include <iostream> using namespace STD; int gcd (int A, int B) {If (B = 0) return a; return gcd (B, A % B );} int main () {int S, N, M; while (CIN> S> N> M, S) {S/= gcd (S, N ), m); If (S & 1) cout <"no" <Endl; else cout <S-1 <Endl;} return 0 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.