社区讨论

95分第一个点wa,求助

P7913[CSP-S 2021] 廊桥分配参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@lo1z8mpx
此快照首次捕获于
2023/10/23 05:24
2 年前
此快照最后确认于
2023/11/03 05:49
2 年前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
const int maxN = 100005;
long long n, m1, m2, op, a[100005], b[100005], ans;
char buf[1 << 20], * _now = buf, * _end = buf;
inline char _getchar() {
    return _now == _end && (_end = (_now = buf) + fread(buf, 1, 1 << 20, stdin), _now == _end) ? EOF : *_now++;
}
inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch>'9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        x = x * 10 + ch - '0', ch = getchar();
    return x * f;
}
inline void write(int x) {
	static int sta[35];
	int top=0;
	do 
	{
		sta[top++]=x%10, x/=10;
	} while(x);
	while(top) putchar(sta[--top]+'0');
}
struct node
{
    int s, t;
}dm[maxN], in[maxN];
struct ont
{
    int l, i;
}f;
vector<ont>dmn, inn;
bool cmp(node x, node y)
{
    return x.s < y.s;
}
int main()
{
    n = read(), m1 = read(), m2 = read();
    for (int i = 1; i <= m1; i++)
    {
        dm[i].s = read();
        dm[i].t = read();
    }
    for (int i = 1; i <= m2; i++)
    {
        in[i].s = read();
        in[i].t = read();
    }
    sort(dm + 1, dm + 1 + m1, cmp);
    sort(in + 1, in + 1 + m2, cmp);
    for (int i = 1; i <= m1; i++)
    {   
		op = 0;
        for (int j = 0; j < dmn.size(); j++)
        {
            if (dm[i].s > dmn[j].l)//if the last plane has already left;
            {
                dmn[j].l = dm[i].t;
                dmn[j].i++;
                op = 1;
                goto loop;
            }
        }
    loop:;
        f = { dm[i].t,1 };
        if (!op)
        {
            dmn.push_back(f);
        }
    }
    for (int i = 1; i <= m2; i++)
    {
        op = 0;
        for (int j = 0; j < inn.size(); j++)
            if (in[i].s > inn[j].l)
            {
                inn[j].l = in[i].t;
                inn[j].i++;
                op = 1;
                break;
            }
        f = { in[i].t,1 };
        if (!op)
        {
            inn.push_back(f);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        f = { 0,0 };
        inn.push_back(f);
        dmn.push_back(f);
    }
    for (int i = 1; i <= n; i++)
    {
        a[i] = a[i - 1] + dmn[i-1].i;
    }
    for(int i=1; i<=n; i++)
    {
    	cout<<a[i]<<" ";
    }
    cout<<endl;
    for (int i = 1; i <= n; i++)
    {
        b[i] = b[i - 1] + inn[i - 1].i;
    }
    for(int i=1; i<=n; i++)
    {
    	cout<<b[i]<<" ";
    }
    cout<<endl;
    for (int i = 1; i <= n; i++)
    {
        ans = max(ans, a[i] + b[n - i]);
    }
    write(ans);
    return 0;
}

回复

1 条回复,欢迎继续交流。

正在加载回复...