## SDUT 2021 Spring Individual Contest(for 20) - 7 补题

Question A A. ​​Zero Array
idea: If it is 1 to modify the array as required, if it is 2, find the minimum number of operands required to make the array become 0 array. Turning an array into an array is to count how many different numbers there are. The number of the same number is meaningless. The first pit is that the number entered can be 0. If it is 0, it does not need to be counted. For each operation of 1 you need to re-count how many different numbers there are. If you use an array to store it, it will definitely time out, so we use a map here. The second pitfall is to add fast read if you use cincout, otherwise it will time out.

``````#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
map<int,int> mp;
int a[N];
int main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{

mp.clear();
long long n,q;
cin>>n>>q;
long long i;
long long res=0;
for(i=1;i<=n;i++)
{

int x;
cin>>x;
a[i]=x;
if(x&&mp[x]==0)
res++;
mp[x]++;
}
while(q--)
{

int m;
cin>>m;
if(m==1)
{

long long p,v;
cin>>p>>v;
long long ans=a[p];
if(v&&mp[v]==0)
res++;
mp[v]++;
a[p]=v;
mp[ans]--;
if(ans&&mp[ans]==0)
{

res--;
}
}
else
{

cout<<res<<endl;
}
}
}
return 0;
}
``````

Problem C C. Intersections
ideas: intersecting line number is the number of the first row in the right of each count how many the number, the number appears to the left in the second row, the reverse logarithmic transformation for the sake of
not making the Reason: I only thought of violence (two-layer cycle), but did not think that it could be solved by reverse order.

``````#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],mp[N],c[N];
long long  ans;
void _sort(int l,int r)
{

if(l==r)
return ;
int mid=l+r>>1;
_sort(l,mid);
_sort(mid+1,r);
int i=l,j=mid+1,k=l;
while(i<=mid&&j<=r)
{

if(a[i]<=a[j])
c[k++]=a[i++];
else
{

c[k++]=a[j++];
ans += (mid - i + 1);
}
}
while(i<=mid)
{

c[k++]=a[i++];
}
while(j<=r)
{

c[k++]=a[j++];
}
for( i=l;i<=r;i++)
{

a[i]=c[i];
}
}
int main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{

int n;
cin>>n;
for(int i=1;i<=n;i++)
{

int x;
cin>>x;
mp[x]=i;
}
for(int i=1;i<=n;i++)
{

int x;
cin>>x;
a[i]=mp[x];
}
ans=0;
_sort(1,n);
cout<<ans<<endl;
}
return 0;
}
``````

Question D D. Balloons
idea: direct violence cycle if a[i]>0, add one to the result

``````#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
int a[N];
int main()
{

int t;
cin>>t;
while(t--)
{

int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
int res=0;
for(int i=1;i<=n;i++)
{

if(a[i]>0)
res++;
}
cout<<res<<endl;
}
return 0;
}
``````

Question F. Working Time
Idea: For the convenience of calculation, install the start time and end time into the minute system, calculate the total number of working minutes, and then divide it by 60 for comparison.

``````#include<bits/stdc++.h>
using namespace std;
int main()
{

int t;
cin>>t;
while(t--)
{

int n,m;
cin>>n>>m;
int res=0;
while(n--)
{

string a,b;
cin>>a>>b;
int sum1=(a[0]-'0')*10+(a[1]-'0');
sum1=sum1*60;
sum1+=(a[3]-'0')*10+(a[4]-'0');
int sum2 = (b[0] - '0') * 10 + (b[1] - '0');
sum2 = sum2 * 60;
sum2 += (b[3] - '0') * 10 + (b[4] - '0');
res+=sum2-sum1;
}
res/=60;
if(res>=m)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
``````

Question H H. Cube
idea: Given the area of ​​a square, divide by 6 to become the area of ​​each surface, and then extract the length of each side from the square root

``````#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
int a[N];
int main()
{

int t;
cin>>t;
while(t--)
{

int a;
cin>>a;
a=a/6;
cout<<sqrt(a)<<endl;
}
return 0;
}
``````

Question I I. Circles
idea: The final area formula that can be pushed out is d*d/2, but the point is to control the error, and finally keep the decimal, and add a quick-reading template

``````#include<bits/stdc++.h>
using namespace std;
int main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{

long long a,b,d;
cin>>a>>b>>d;
double sum=d*d/2.0;
cout<<fixed<<setprecision(7)<<sum<<endl;
}
return 0;
}
``````

Question J J. Smallest Difference
Idea: If you want any two-digit difference <=1, it can only be an array of adjacent two-digit numbers.

``````#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
int a[N],b[N];
int main()
{

int t;
cin>>t;
while(t--)
{

memset(b,0,sizeof(b));
int n;
cin>>n;
int mmax=0;
for(int i=1;i<=n;i++)
{

cin>>a[i];
if(mmax<a[i])
mmax=a[i];
}
for(int i=1;i<=n;i++)
{

b[a[i]]++;
}
int res=0;
for(int i=1;i<mmax;i++)
{

res=max(b[i]+b[i+1],res);
}
cout<<res<<endl;
}
return 0;
}
``````

### Guess you like

Origin blog.csdn.net/weixin_51768569/article/details/114943631
Recommended
Ranking
Daily