A
区间求交
T = int(input())
for kase in range(T):
a, b, c, r = [int(x) for x in input().split()]
a, b = min(a,b), max(a,b)
x, y = c-r, c+r
u, v = max(a,x), min(b,y)
# print( (x,y) )
print( (b-a)-max(0,v-u) )
B
排序,最后的方案肯定是前面的一小段每个都单独买,后面跟着若干个长度为
的段
枚举前面这个小段的长度,然后
算一下
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 1000010
#define maxe 1000010
#define cl(x) memset(x,0,sizeof(x))
#define rep(_,__) for(_=1;_<=(__);_++)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
ll c, f(1);
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
for(;isdigit(c);c=getchar())x=x*10+c-0x30;
return f*x;
}
ll n, p, k, a[maxn], s[maxn];
bool check(ll m)
{
ll i, cost=0;
for(i=m;i>0;i-=k)
{
if(i>=k)cost+=a[i];
else cost+=s[i];
}
return cost<=p;
}
int main()
{
ll T=read(), i, j, l, r, mid, ans;
while(T--)
{
n=read(), p=read(), k=read();
rep(i,n)a[i]=read();
sort(a+1,a+n+1);
rep(i,n)s[i]=s[i-1]+a[i];
ans=0;
for(i=0;i<k;i++)
{
ll cost=s[i];
if(cost>p)break;
ans=max(ans,i);
for(j=i+k;j<=n and cost+a[j]<=p;j+=k)cost+=a[j], ans=max(ans,j);
}
printf("%lld\n",ans);
}
return 0;
}
C
根据贪心策略,离开考场的只需要考虑
和
然后扫一遍算一算即可
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 1000010
#define maxe 1000010
#define cl(x) memset(x,0,sizeof(x))
#define rep(_,__) for(_=1;_<=(__);_++)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
ll c, f(1);
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
for(;isdigit(c);c=getchar())x=x*10+c-0x30;
return f*x;
}
pii p[maxn];
ll n, T, res[2];
int t[maxn];
struct Lisan
{
int tmp[maxn], tot;
void clear(){tot=0;}
void insert(int x){tmp[++tot]=x;}
void run()
{
sort(tmp+1,tmp+tot+1);
tot=unique(tmp+1,tmp+tot+1)-tmp-1;
}
void lisan(int *a, int len)
{
for(int i=1;i<=len;i++)a[i]=lower_bound(tmp+1,tmp+tot+1,a[i])-tmp;
}
int lisan(int x)
{
return lower_bound(tmp+1,tmp+tot+1,x)-tmp;
}
}ls;
int main()
{
ll i, j, ans, a, b, last, must, cnt;
T=read();
while(T--)
{
n=read(), last=read(), a=read(), b=read();
rep(i,n)p[i].second=read();
rep(i,n)p[i].first=read();
res[0]=res[1]=0;
rep(i,n)res[p[i].second]++;
ls.clear();
ls.insert(last), ls.insert(last-1);
rep(i,n)ls.insert(p[i].first-1), ls.insert(p[i].first);
ls.run();
sort(p+1,p+n+1);
must = 0;
ans = 0;
j = 1;
rep(i,ls.tot)
{
while(j<=n and p[j].first<=ls.tmp[i])
{
if(p[j].second)must += b;
else must += a;
res[ p[j].second ]--;
j++;
}
if(must <= ls.tmp[i])
{
ll t = ls.tmp[i] - must;
ll easy = min( res[0], t/a);
t -= easy*a;
ll hard = min( res[1], t/b );
ans = max(ans, j-1 + easy + hard);
}
}
printf("%lld\n",ans);
}
return 0;
}
D
好难啊qwq,没做出来
先问一个a
,得到一个答案
,这个时候除非串是纯b
,不然
应该就等于长度
在问一下
个b
,返回了
,如果
,那么就结束了,否则串长度我们算出来了是
接下来的主要思路就是先用全是a
的串,然后一个字母一个字母改成b
可以算出串中总共有
个b
每次修改一个a
,然后看下编辑距离有没有减小,减小了那这个位置就是b
,否则是a
恰好 次
import sys
def ask(s):
print(s)
sys.stdout.flush()
return int( input() )
a = ask('a')
if a==0:
exit(0)
b = ask('b'*a)
if b==0:
exit(0)
n = a+1
s = 'a'*n
now = n-b
if now==0:
ask('a'*n)
exit(0)
for i in range(n-1):
t = ask(s[:i]+'b'+s[i+1:])
if t==0:
exit(0)
if t < now:
s = s[:i]+'b'+s[i+1:]
now = t
if now>0:
ask(s[:-1]+'b')
E
赛后过题,最为致命
看一下图,会发现,除了边界之外,其它所有的边都出现在了两个三角形中
这样就可以直接得出边界了
然后,每次找到一个点,满足这个点只在一个三角形中出现过,把这个三角形删去,并更新每个点所在的三角形个数,按照这个顺序操作得到的就是切饼的次序
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 1000010
#define maxe 1000010
#define cl(x) memset(x,0,sizeof(x))
#define rep(_,__) for(_=1;_<=(__);_++)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
ll c, f(1);
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
for(;isdigit(c);c=getchar())x=x*10+c-0x30;
return f*x;
}
struct Graph
{
int etot, head[maxn], to[maxe], next[maxe], w[maxe];
void clear(int N)
{
for(int i=1;i<=N;i++)head[i]=0;
etot=0;
}
void adde(int a, int b, int c=0){to[++etot]=b;w[etot]=c;next[etot]=head[a];head[a]=etot;}
#define forp(pos,G) for(auto p=G.head[pos];p;p=G.next[p])
}G;
map<pll,ll> cnt;
vector<ll> tnr[maxn];
set<ll> s[maxn];
ll n, x[maxn], y[maxn], z[maxn], vis[maxn];
void mov(ll id)
{
s[x[id]].erase(id);
s[y[id]].erase(id);
s[z[id]].erase(id);
}
pll kou(vector<ll> v, ll x)
{
vector<ll> lis;
for(auto t:v)if(t!=x)lis.emb(t);
return pll( lis[0], lis[1] );
}
void dfs(ll pos)
{
vis[pos]=1;
printf("%lld ",pos);
if(!vis[ tnr[pos][0] ])dfs(tnr[pos][0]);
if(!vis[ tnr[pos][1] ])dfs(tnr[pos][1]);
}
void bfs()
{
ll i;
queue<ll> q;
rep(i,n)if(s[i].size()==1)q.em(i);
while(!q.empty())
{
auto now=q.front(); q.pop();
if(s[now].size()==0)continue;
auto id=*s[now].begin();
printf("%lld ",id);
mov(id);
auto pr = kou({x[id],y[id],z[id]},now);
if(s[pr.first].size()==1)q.em(pr.first);
if(s[pr.second].size()==1)q.em(pr.second);
}
}
pll sorted(pll x)
{
return pll( min(x.first,x.second), max(x.first,x.second) );
}
int main()
{
ll T=read(), i, a, b, c;
while(T--)
{
n=read();
cnt.clear();
G.clear(n);
rep(i,n)tnr[i].clear(), s[i].clear(), vis[i]=0;
rep(i,n-2)
{
a=read(), b=read(), c=read();
cnt[sorted(pll(a,b))]++;
cnt[sorted(pll(b,c))]++;
cnt[sorted(pll(a,c))]++;
s[a].em(i), s[b].em(i), s[c].em(i);
x[i]=a, y[i]=b, z[i]=c;
}
for(auto pr:cnt)
{
if(pr.second==1)
tnr[pr.first.first].emb(pr.first.second),
tnr[pr.first.second].emb(pr.first.first);
}
dfs(1); putchar(10);
bfs(); putchar(10);
}
return 0;
}
总评
这场 质量不错,思考量和创新性都高出很多其他的
只是可惜难度太低