A题:dfs,从打到搜索
#include
#include
#include
#include
#include
#include
#include
#include
B题:ac自动机,将前后相减等到的串去匹配,由于有负值,所以用结构体,用map存边。
#include
#include
#include
#include
#include
#include
#include
#include
D题:二分图,先判断二分图,然后二分匹配。
#include
#include
#include
#include
#include
#include
#include
#include
#include
E题:
#include
#include
#include
#include
using namespace std;
int a[2][2], b[2][2], c[2][2], g[2];
#define exp 1e-6
int main()
{
int n;
while (~scanf("%d", &n))
{
int x, y, z, m;
a[0][0] = a[1][1] = a[1][0] = a[1][1] = 0;
b[0][0] = b[1][1] = b[1][0] = b[1][1] = 0;
c[0][0] = c[1][1] = c[1][0] = c[1][1] = 0;
g[0] = g[1] = 0;
for (int i = 0; i < n; i++)
{
scanf("%d%d%d%d", &x, &y, &z, &m);
a[m][x]++;
b[m][y]++;
c[m][z]++;
g[m]++;
}
scanf("%d%d%d", &x, &y, &z);
double xx, yy;
xx = (a[0][x] + 1.0 / n)*b[0][y] / n*c[0][z] / n*g[0];
yy = (a[1][x] + 1.0 / n)*b[1][y] / n*c[1][z] / n*g[1];
if (yy - xx > exp)
puts("Come on guys,you can do it!");
else
puts("Poor guys,you can go back to sleep now..");
}
}
F题:结论题
G题:TL
H题:ORZ
I:贪心,根据上车的人数从小到大排序,然后从终点站到这往前推,如果出现负值说明这种情况无解。
#include
#include
#include
#include
using namespace std;
struct node
{
int x, y;
}a[110000];
bool cmp(node a, node b)
{
return a.y < b.y;
}
int main()
{
int n;
while (~scanf("%d", &n))
{
for (int i = 0; i < n; i++)
scanf("%d%d", &a[i].x, &a[i].y);
sort(a, a + n, cmp);
long long sum = 0;
bool flag = true;
if (a[0].y != 0)
puts("No");
else
{
for (int i = 0; i < n; i++)
{
sum -= a[i].y;
if (sum < 0)
{
flag = false;
break;
}
sum += a[i].x;
}
if (flag)
puts("Yes");
else
puts("No");
}
}
}
J题:乱搞
#include
#include
#include
#include
#include
using namespace std;
int x[1100000], y[1100000];
int main()
{
int n;
while (~scanf("%d", &n))
{
for (int i = 0; i < n; i++)
scanf("%d%d", &x[i], &y[i]);
sort(y, y + n);
int k = y[n / 2];
long long sum = 0;
for (int i = 0; i < n; i++)
sum += abs(y[i] - k);
printf("%lld\n", sum);
}
}