思维加枚举
题意 :足球赛,赢平所得到的分数分别为w和d,w>d,分别求赢平输的场数,输出一组即可,即x+y+z=n 且 xw+yd=p的一组解。
可以扩展公约数做,但由于注意到d和w<1e5的条件,可以枚举。
个人理解是由于dw=wd 就是说你用w场平的所得分和d场赢所得分是一样,所以我们就可以调整平的场数,由于题目有这样一句话
Note that w>dw>d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw.
所以我们尽量让平的场数少,介于[0,w-1]之间,(显然平的场数超过这个区间的时候,我可以用d场赢的来替代,且由于d
所以就是枚举平的场数呀,大概记录一下思维。
1 #include
2 #define debug(x) cout << #x << ": " << x << endl
3 using namespace std;
4 typedef long long ll;
5 const int MAXN=2e5+7;
6 const int INF=0x3f3f3f3f;
7
8 int main()
9 {
10 ios::sync_with_stdio(false);
11 cin.tie(0);
12 ll n,p,d,w;
13 cin>>n>>p>>w>>d;
14 ll x,y,z;
15 int ok=0;
16 for(int i=0;ii)
17 {
18 if((p-(i*d))%w==0)
19 {
20 x=(p-i*d)/w;
21 y=i;
22 z=n-x-y;
23 if(x>=0 && y>=0 && z>=0) {ok=1;break;}
24 }
25 }
26 if(!ok) cout<<-1<<endl;
27 else cout<' '<' '<endl;
28 return 0;
29 }
View Code