用一根平行x轴的直线扫描三角形,求交点,然后计算中间点的数,求和即可。
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("fence9.in");
ofstream fout("fence9.out");
#ifdef _DEBUG
#define out cout
#define in cin
#else
#define out fout
#define in fin
#endif
void solve()
{
int n,m,p;
in>>n>>m>>p;
int res = 0;
int s,e;
for(int y=1;y<m;++y){
s = n*y/m+1;
e = ( y*(n-p)%m==0 ) ? (y*(n-p)/m-1+p) : floor(((double)y*(n-p)/m)+p);
// out<<y<<" "<<s<<" "<<e<<endl;
res += max(0,(e-s+1));
}
out<<res<<endl;
}
int main(int argc,char *argv[])
{
solve();
return 0;
}