https://www.jisuanke.com/contest/1557?view=challenges
i-Characters with Hash
签到题,简单模拟
注意0删掉前导0还是0
ac:
#include<bits/stdc++.h>
#define maxn 1000007
using namespace std;
char ctr,str[maxn];
int gg[maxn];
int main()
{
int t,n,x,cnt;
scanf("%d",&t);
while(t--)
{
memset(str,0,sizeof(str));
memset(gg,0,sizeof(gg));
cnt=0;
scanf("%d",&n);
getchar();
scanf("%c",&ctr);
getchar();
scanf("%s",&str);
for(int i=0;i<n;i++)
{
x=ctr-str[i];
if(x<0)
x=-x;
if(x>9)
{
gg[cnt++]=x/10;
gg[cnt++]=x%10;
}
else {
gg[cnt++]=0;
gg[cnt++]=x;
}
}
int i;
for(i=0;i<cnt;i++)
if(gg[i]!=0)
break;
if(2*n==i)//0删除前导0还是0.
printf("1\n");
else printf("%d\n",2*n-i);
}
return 0;
}
f-Features Track
签到题-简单模拟
计算连续相等的点的最大次数,用map存储
ac:
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=100005;
struct node
{
LL x,y;
node(LL xxx,LL yyy)
{
x=xxx;
y=yyy;
}
friend bool operator <(node a,node b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
};
map<node,int> mp1;
map<node,int> mp2;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
mp1.clear();
mp2.clear();
LL ans=0;
for(int i=0;i<n;i++)
{
LL k;
cin>>k;
while(k--)
{
LL x,y;
cin>>x>>y;
LL v=mp1[node(x,y)]+1;
mp2[node(x,y)]=v;
ans=max(ans,v);
}
mp1=mp2;
mp2.clear();
}
cout<<ans<<endl;
}
return 0;
}
g-Trace
简单模拟
因为不会出现覆盖情况,所以我们从后往前计算,用set存储已经加入的线段,所以直接查找比插入边小的边,sum+=插入边-小边
ac:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int n,x[50001]={0},y[50001]={0};
ll sum=0;
set<int> st,ct;
st.insert(0);
ct.insert(0);
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&x[i],&y[i]);
set<int>::iterator j,k;
for(int i=n-1;i>=0;i--)//因为不会出现完全覆盖,所以直接查找比插入边小的边,插入边-小边
{
st.insert(x[i]);
j=st.lower_bound(x[i]);
k=j--;
sum+=*k-*j;
ct.insert(y[i]);
j=ct.lower_bound(y[i]);
k=j--;
sum+=*k-*j;
}
printf("%lld\n",sum);
return 0;
}