赞
踩
题意 :
思路 :
语法 :
for (int i = 0; i < n;)
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 510;
int c_max, d, d_avg, n;
struct Stop
{
double p, d;
bool operator< (const Stop& t) const
{
if (d != t.d) return d < t.d;
return p < t.p;
}
}s[N];
int main()
{
scanf("%d%d%d%d", &c_max, &d, &d_avg, &n);
for (int i = 0; i < n; i ++ ) scanf("%lf%lf", &s[i].p, &s[i].d);
s[n] = {0, (double)d};
sort(s, s + n + 1);
if (s[0].d)
{
puts("The maximum travel distance = 0.00");
return 0;
}
double res = 0, oil = 0;
for (int i = 0; i < n;)
{
int k = -1;
for (int j = i + 1; j <= n && s[j].d - s[i].d <= c_max * d_avg; j ++ )
{
if (s[j].p <= s[i].p)
{
k = j;
break;
}
else if (k == -1 || s[k].p > s[j].p)
k = j;
}
if (k == -1)
{
printf("The maximum travel distance = %.2lf\n", s[i].d + (double)c_max * d_avg);
return 0;
}
if (s[k].p <= s[i].p)
{
res += ((s[k].d - s[i].d) / d_avg - oil) * s[i].p;
oil = 0;
i = k;
}
else
{
res += (c_max - oil) * s[i].p;
oil = c_max - (s[k].d - s[i].d) / d_avg;
i = k;
}
}
printf("%.2lf\n", res);
}
题意 :
思路 :
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
int n, m;
ll a[N], b[N];
int main()
{
scanf("%d", &n);
for (int i = 0; i < n && scanf("%lld", &a[i]); i ++ );
scanf("%d", &m);
for (int i = 0; i < m && scanf("%lld", &b[i]); i ++ );
sort(a, a + n);
sort(b, b + m);
ll sum = 0;
for (int i = 0, j = 0; i < n && j < m && a[i] < 0 && b[j] < 0; i ++ , j ++ ) sum += a[i] * b[j];
for (int i = n - 1, j = m - 1; i >= 0 && j >= 0 && a[i] > 0 && b[j] > 0; i -- , j -- ) sum += a[i] * b[j];
printf("%lld\n", sum);
}
题意 :
思路 :
#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int p[N];
int main()
{
int n; scanf("%d", &n);
int id;
for (int i = 0; i < n; i ++ )
{
scanf("%d", &id);
p[id] = i;
}
int res = 0;
for (int i = 0; i < n; )
{
while (p[0]) swap(p[0], p[p[0]]), res ++ ;
while (i < n && p[i] == i) i ++ ;
if (i < n) swap(p[0], p[i]), res ++ ;
}
printf("%d", res);
}
题意 :
思路 :
语法 :
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e4 + 10;
double a[N];
int main()
{
int n; scanf("%d", &n);
for (int i = 0; i < n && scanf("%lf", &a[i]); i ++ );
sort(a, a + n);
for (int i = 1; i < n; i ++ ) a[0] = (a[0] + a[i]) / 2;
printf("%d", (int)a[0]);
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。