usaco Electric Fence

這道題比較簡單。

不過還是得注意考慮幾種特殊情況,如下所示:


還有就是得去掉相交的點即可。

代碼如下:

/*
ID: guo geer
PROG: fence9
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

int main()
{
    freopen("fence9.in","r",stdin);
    freopen("fence9.out","w",stdout);
    int n, m, p;
    while(scanf("%d %d %d", &n,&m,&p)==3)
    {
           int res = 0;

           if(n != 0)
           {
                 for(int i=1; i<n; i++) 
                 {
                       res += (i*m)/n;  
                       if((i*m)%n == 0)
                       res --;
                 }
           }
           if(n < p)
           {
                for(int i=1; i<p-n; i++)
                {
                       res += (i*m)/(p-n);  
                       if((i*m)%(p-n) == 0)
                       res --;
                }            
           }

           else if(n > p)
           {
                for(int i=1; i<n-p; i++)
                {
                       res -= (i*m)/(n-p);  
                }
           }
           if(n>0&&p>n) res += m-1;
           printf("%d\n", res);
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章