zoukankan      html  css  js  c++  java
  • 【codeforces 499C】Crazy Town

    【题目链接】:http://codeforces.com/problemset/problem/499/C

    【题意】

    一个平面,被n条直线分成若干个块;
    你在其中的某一块,然后你想要要到的终点在另外一个块;
    给出起点坐标(x0,y0),终点坐标(x1,y1);
    每次你能从一个块移动到相邻的块;
    问你最少需要穿过多少条直线,才能到达终点所在的块;

    【题解】

    枚举每一条直线;
    如果这两个点在这条直线的两边;(即不在一边);
    那么肯定最后是需要穿过这条直线的(才能走在一起);
    所以答案递增;
    代入一般式,看看符号是不是不同即可;
    因为有说不在线上,所以不用考虑为0的情况;

    【Number Of WA

    0

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define ms(x,y) memset(x,y,sizeof x)
    #define Open() freopen("F:\rush.txt","r",stdin)
    #define Close() ios::sync_with_stdio(0),cin.tie(0)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 110;
    
    LL x1,y1,x2,y2,a,b,c;
    int n,ans = 0;
    
    int main()
    {
        //Open();
        Close();//scanf,puts,printf not use
        //init??????
        cin >> x1 >> y1;
        cin >> x2 >> y2;
        cin >> n;
        rep1(i,1,n)
        {
            cin >> a >> b >> c;
            LL temp1 = a*x1+b*y1+c;
            LL temp2 = a*x2+b*y2+c;
            if ( (temp1<0 && temp2>0) || (temp1>0 && temp2<0))
                ans++;
        }
        cout << ans << endl;
        return 0;
    }
  • 相关阅读:
    JQuery使用总结
    JS应用总结
    Base64数据转成Excel,并处理Excel的格式
    HTTP压缩
    谷歌开发工具解析
    .Net LIst排重
    MySql日志系统
    .Net生成PDF流
    Mysql MVCC
    JAVA期末综合课程设计
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626302.html
Copyright © 2011-2022 走看看