A. Dead Pixel 题目链接
#include
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn=1e9;
int a,b,x,y;
void solve()
{
cin>>a>>b>>x>>y;
x++,y++;
int n,m;
n=max(a-x,x-1);
m=max(b-y,y-1);
printf("%d\n",max(n*b,m*a));
}
int main()
{
ll T;
scanf("%lld\n",&T);
while(T--)
solve();
return 0;
}
B. Homecoming 题目链接
#include
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn=1e9;
int a,b,p;
string s;
void solve()
{
cin>>a>>b>>p>>s;
int len=s.size();
int ans=len;
int c;
if(s[len-1-1]=='A')
s[len-1]='B';
else
s[len-1]='A';
for(int i=len-1;
i>=1;
i--)
{
if(s[i]!=s[i-1])
{
if(s[i-1]=='A')
c=a;
else
c=b;
if(p
C. Restoring Permutation 题目链接
#include
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn=100+10;
int n;
int b[maxn];
int ans[2*maxn];
void solve()
{
cin>>n;
mapm;
m.clear();
for(int i=1;
i<=n;
i++)
{
cin>>b[i];
m[b[i]]=1;
ans[2*i-1]=b[i];
}
for(int i=1;
i<=n;
i++)
{
for(int j=b[i]+1;
;
j++)
{
if(j>2*n)
{
puts("-1");
return;
}
if(m[j]==0)
{
m[j]=1;
ans[2*i]=j;
break;
}
}
}
cout<
D. Recommendations 题目链接
写法1:
并查集
#include
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn=2e5+10;
int n;
mapfa;
struct node
{
ll num;
int t;
}a[maxn];
bool cmp(node a,node b)
{
return a.t==b.t?a.numb.t;
}
int findf(int x)
{
return fa[x]==0?x:fa[x]=findf(fa[x]);
}
void mix(int x,int y)
{
int xx=findf(x);
int yy=findf(y);
if(xx!=yy)
fa[xx]=yy;
}
void solve()
{
cin>>n;
for(int i=1;
i<=n;
i++)
cin>>a[i].num;
for(int i=1;
i<=n;
i++)
cin>>a[i].t;
sort(a+1,a+1+n,cmp);
ll ans=0;
for(int i=1;
i<=n;
i++)
{
int res=findf(a[i].num);
if(res!=a[i].num)
ans+=1ll*(res-a[i].num)*a[i].t;
mix(res,res+1);
}
cout<
【Codeforces Round #623】写法2:
STL 优先队列
#include
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
struct node
{
int num;
int time;
}a[maxn];
int cmp(node a,node b)
{
if(a.num==b.num)
return a.time>n;
for(i=1;
i<=n;
i++)
cin>>a[i].num;
for(i=1;
i<=n;
i++)
cin>>a[i].time;
sort(a+1,a+n+1,cmp);
int now=0;
ll sum=0,all=0;
mapmp;
priority_queueq;
for(i=1;
i<=n;
i++)
{
if(a[i].num==a[i-1].num)
{
if(a[i].time
推荐阅读
- 补题|Educational Codeforces Round 85 (Rated for Div. 2)
- everyday|Codeforces Round #634 (Div. 3)
- 补题|Codeforces Round #635 (Div. 2)
- 补题|Codeforces Round #633 (Div. 2)
- 补题|Omkar and Bed Wars
- Codeforces Round #609 (Div. 2)
- 牛妹爱数列