[BZOJ 1441]Min
转载请注明出处:http://danihao123.is-programmer.com/
这个问题看似无从下手。
我们可以先取[tex]n=2[/tex],然后你就发现你似乎要解[tex]A_{1}X_{1}+A_{2}X_{2}>0[/tex],而且还要求[tex]S[/tex]最小?你想到了什么?扩展欧几里得?对头!
由扩欧推广可得答案就是所有数的最大公约数。
代码:
/************************************************************** Problem: 1441 User: danihao123 Language: C++ Result: Accepted Time:0 ms Memory:820 kb ****************************************************************/ #include <cstdio> #include <cmath> #include <algorithm> using namespace std; int gcd(int a,int b){ return b==0?a:gcd(b,a%b); } int main(){ register int ans,i; int n,temp; scanf("%d",&n); scanf("%d",&temp); ans=abs(temp); for(i=2;i<=n;i++){ scanf("%d",&temp); ans=gcd(ans,abs(temp)); } printf("%d\n",ans); return 0; }
Jul 04, 2023 11:35:58 AM
Is an initiative of skilled journalists who have come together for specialised samplepaper.in news coverage of recent events across the country.is a newspaper that is passionate about producing education news in the public interest and has a wide range of journalism interests. Our team is made up of professional writers and citizen journalists with diverse media interests