网址:https://www.nowcoder.com/acm/contest/201#question
A.签到
手速石头剪刀布
#include <cstdio> #include <algorithm> using namespace std; int main() { int a, b, c, d, e, f; scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f); printf("%d ", min(a, e)+min(b, f)+min(c, d)); }
E.签到,贪心
#include <cstdio> #include <algorithm> #include <cmath> using namespace std; int a[1000010]; int main() { int n, m; scanf("%d%d", &n, &m); for(int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a,a+n); int ans = 1; for(int i = 1; i < n; i++) { if(abs(a[i] - a[i-1]) > m) ans++; } printf("%d ", ans); }
L.看似计算几何的最短路
题意:平面上有一条直线和n个圆,从一条直线走到另一条直线,在圆上和直线上走不消耗,其他地方消耗==路程,问最少消耗
思路:因为在圆上走不消耗,就相当于一个点,把圆抽象成点,相交或包含的圆就是一个点,相离的圆抽象成距离为(两圆圆心距离 - r1 - r2)的两个点,跑最短路
队友写的,不放代码了,耶
C.暴力枚举。。。。。。
题意:满足ax+by=c的整数x, y中,能使p2*x2+p1*x+q2*y2+q1*y取最小值的那组x, y 输出这个最小值
无言以对。。。
就当学习一波拓展欧几里得吧
拓展欧几里得,就是求关于x,y的方程 ax + by = gcd(a,b) 的所有整数解
LL exgcd(LL a,LL b,LL &x,LL &y) { if(a==0 && b==0) return -1; if(b==0) { x=1, y=0; return a; } LL d = exgcd(b, a%b, y, x); y -= a/b*x; return d; }
对于方程a * x + b * y = c 来说,如果c % gcd(a,b) != 0,即c不是gcd的整数倍,则无解。
如果c % gcd(a,b) == 0 且 c / gcd(a,b) = t,那么求出方程 a * x + b * y = gcd(a,b)的所有解x,y,将x,y乘上t,对应的x’,y’即是方程a * x + b * y = t * gcd(a,b)的解
暴力枚举所有的x……
#include <cmath> #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; using namespace std; LL exgcd(LL a,LL b,LL &x,LL &y) { if (a==0 && b==0) return -1; if (b==0) { x=1,y=0; return a; } LL d=exgcd(b,a%b,y,x); y-=a/b*x; return d; } LL p1,p2,q1,q2; LL cal(LL x, LL y) { return p2*x*x+p1*x+q2*y*y+q1*y; } int main() { LL a,b,c; LL x,y; scanf ("%lld%lld%lld%lld%lld%lld%lld",&a,&b,&c,&p1,&p2,&q1,&q2); LL g=exgcd(a,b,x,y); if (c%g!=0 || g==-1) { printf("Kuon "); return 0; } LL res = 1000000000000000000LL; for(x = -100000; x <= 100000; x++) { if((c-a*x)%b) continue; y = (c-a*x)/b; res = min(res, cal(x, y)); } printf("%lld ", res); }