牛客國慶集訓派對Day1(A、C、E、L)
阿新 • • 發佈:2018-12-13
#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; #define clr(a) memset(a,0,sizeof(a)) #define line cout<<"-----------------"<<endl; typedef long long ll; const int maxn = 1e5+10; const int MAXN = 1e6+10; const int INF = 0x3f3f3f3f; const int MOD = 1e9+7; const int N = 1010; int n; int main(){ int a, b, c, d, e,f; cin >> a >> b >> c >> d >> e >> f; int cnt = 0; cnt += min(a, e); cnt += min(b, f); cnt += min(c, d); cout << cnt << endl; return 0; }
#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; #define clr(a) memset(a,0,sizeof(a)) #define line cout<<"-----------------"<<endl; typedef long long ll; const int maxn = 1e5+10; const int MAXN = 1e6+10; const int INF = 0x3f3f3f3f; const int MOD = 1e9+7; const int N = 1010; 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; } int main(){ ll x, y, a, b, c, p1, p2, q1, q2; cin>>a>>b>>c; cin>>p1>>p2; cin>>q1>>q2; ll _ = exgcd(a, b, x, y); if(c % _) puts("Kuon"); else{ ll s=((2*a*c*q2)/(b*b)+a*q1/b-p1)/(2*(p2+(a*a*q2)/b*b)); ll s1=s,s2=s; while((c-a*s1)%b) s1--; while((c-a*s2)%b) s2++; ll a1=(c-a*s1)/b; ll a2=(c-a*s2)/b; ll res1=(p1*s1+p2*s1*s1+q2*a1*a1+q1*a1); ll res2=(p1*s2+p2*s2*s2+q2*a2*a2+q1*a2); cout<<min(res1, res2)<<endl; } return 0; }
#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; #define clr(a) memset(a,0,sizeof(a)) #define line cout<<"-----------------"<<endl; typedef long long ll; const int maxn = 1e5+10; const int MAXN = 1e6+10; const int INF = 0x3f3f3f3f; const int MOD = 1e9+7; const int N = 1010; int n, m; struct node{ int id, val; bool vis; }p[MAXN]; bool cmp(node a, node b){ return a.val < b.val; } int main(){ scanf("%d%d", &n, &m); for(int i=1; i<=n; i++){ scanf("%d", &p[i].val); p[i].id = i; } sort(p+1, p+n+1, cmp); int cnt = 1; int pre = p[1].val; int l = pre - m; int r = pre + m; for(int i=2; i<=n; i++){ if(p[i].val <= r && p[i].val >= l) {} else { cnt ++; } pre = p[i].val; l = pre - m; r = pre + m; } cout << cnt << endl; return 0; }
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
#define line cout<<"-----------------"<<endl;
typedef long long ll;
const int maxn = 1e5+10;
const int MAXN = 1e6+10;
const int MOD = 1e9+7;
const int N = 1010;
const double INF = 1e10 + 10;
const double eps = 1e-4;
int n;
double A, B, C1, C2;
double mapp[N][N], dis[N];
bool vis[N];
struct node{
double x, y ,r;
}p[N];
double getCC(int a, int b){
return sqrt(abs((p[a].x-p[b].x)*(p[a].x-p[b].x)) + abs((p[a].y-p[b].y)*(p[a].y-p[b].y)));
}
double getCL(double A, double B, double c, int v){
return double (abs(p[v].x*A + p[v].y*B + c) / sqrt(A*A + B*B));
}
void Spfa(int u,int v){
memset(vis, false, sizeof(vis));
for(int i=0; i<N; i++) dis[i] = INF;
queue<int> Q;
Q.push(u);
vis[u] = true;
dis[u] = 0;
while(!Q.empty()){
int top = Q.front();
Q.pop();
vis[top] = false;
for(int i=0; i<=n+1; i++){
if(dis[i] > dis[top] + mapp[top][i]){
dis[i] = dis[top] + mapp[top][i];
if(vis[i] == false){
vis[i] = true;
Q.push(i);
}
}
}
}
}
int main(){
scanf("%d%lf%lf%lf%lf", &n, &A, &B, &C1, &C2);
for(int i=1; i<=n; i++)
scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].r);
mapp[0][n+1] = mapp[n+1][0] = abs(C1-C2) / (sqrt(A*A + B*B));
for(int i=1; i<=n; i++){
double t = getCL(A, B, C1, i);
if(t - p[i].r <= eps)
mapp[0][i] = mapp[i][0] = 0;
else
mapp[i][0] = mapp[0][i] = t - p[i].r;
t = getCL(A, B, C2, i);
if(t - p[i].r <= eps)
mapp[n+1][i] = mapp[i][n+1] = 0;
else
mapp[i][n+1] = mapp[n+1][i] = t - p[i].r;
for(int j=i+1; j<=n; j++){
t = getCC(i, j);
if(t - (p[i].r + p[j].r) <= eps)
mapp[i][j] = mapp[j][i] = 0;
else
mapp[i][j] = mapp[j][i] = t - (p[i].r + p[j].r);
}
}
Spfa(0, n+1);
printf("%.6lf\n", dis[n+1]);
return 0;
}