小蒟蒻-周四训练课-第3场总结
liuxiuqi_0203 · · 个人记录
小蒟蒻-周四训练课-第3场总结
- 分数:
190 - 排名:
4
::::info[CF2021B]{open} :::error[错误代码]{open}
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n,x;
int a[1000005];
signed main(){
cin>>t;
while(t--){
cin>>n>>x;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+1+n);
int hz=0;
for(int i=1;i<=n;i++){
if(a[i]==hz){
hz++;
}else if(a[i]==a[i-1]){
int news=a[i]+x;
int l=i,r=n;
while(l+1<r){
int m=(l+r)/2;
if(a[m]<=news){
l=m;
}else{
r=m;
}
}
a[++n]=news;
sort(a+l,a+1+n);
}else{
break;
}
}
cout<<hz<<'\n';
}
return 0;
}
:::
:::success[正确思路和代码]{open}
我们发现,无论如何,答案一定不会超过
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n,x;
int a[200015];
int f[200015];
signed main(){
cin>>t;
while(t--){
cin>>n>>x;
for(int i=0;i<=n;i++){
f[i]=0;
}
for(int i=1;i<=n;i++){
cin>>a[i];
f[min(n+1,a[i])]++;
}
for(int i=0;i<=n+1;i++){
if(f[i]==0){
cout<<i<<'\n';
break;
}else{
if(i+x<=n+1){
f[i+x]+=f[i]-1;
}
}
}
}
return 0;
}
| ::: |
|---|
| ::::info[CF1B]{open} |
| :::error[错误代码]{open} |
| ```cpp |
| #include<bits/stdc++.h> |
| #define int long long |
| using namespace std; |
| int t; |
| string str; |
| bool c; |
| string zh(bool c,string s){ |
| int h=0,l=0; |
| if(c==0){ |
| int yryr; |
| for(int i=1;i<s.size();i++){ |
| if(s[i]>='A'&&s[i]<='Z'){ |
| yryr=i; |
| break; |
| }else{ |
| h=h*10+s[i]-'0'; |
| } |
| } |
| for(int i=yryr+1;i<s.size();i++){ |
| l=l*10+s[i]-'0'; |
| } |
| }else{ |
| int yryr; |
| for(int i=0;i<s.size();i++){ |
| if(s[i]>='0'&&s[i]<='9'){ |
| yryr=i; |
| break; |
| }else{ |
| l=l*26+s[i]-'A'+1; |
| } |
| } |
| for(int i=yryr;i<s.size();i++){ |
| h=h*10+s[i]-'0'; |
| } |
| } |
| //cout<<h<<' '<<l<<'\n'; |
| string str; |
| if(c==1){ |
| str="R"; |
| string sr=""; |
| while(h){ |
| sr=char(h%10+'0')+sr; |
| h=h/10; |
| } |
| str=str+sr+'C'; |
| sr=""; |
| while(l){ |
| sr=char(l%10+'0')+sr; |
| l=l/10; |
| } |
| str+=sr; |
| }else{ |
| str=""; |
| while(l){ |
| str=char((l+25)%26+'A')+str; |
| l/=26; |
| } |
| string sr; |
| while(h){ |
| sr=char(h%10+'0')+sr; |
| h=h/10; |
| } |
| str+=sr; |
| } |
| return str; |
| } |
| signed main(){ |
| cin>>t; |
| while(t--){ |
| cin>>str; |
| if(str[0]=='R'&&str[1]>='0'&&str[1]<='9'){ |
| c=0; |
| }else{ |
| c=1; |
| } |
| cout<<zh(c,str)<<'\n'; |
| } |
| return 0; |
| } |
:::
:::success[正确思路及代码]{open}
先算出属于哪一种,再对症下药,进行转化和再转化。
```cpp
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
string str;
bool c;
void zh(bool c,string s){
int h=0,l=0;
if(c==0){
int yryr;
for(int i=1;i<s.size();i++){
if(s[i]>='A'&&s[i]<='Z'){
yryr=i;
break;
}else{
h=h*10+s[i]-'0';
}
}
for(int i=yryr+1;i<s.size();i++){
l=l*10+s[i]-'0';
}
}else{
int yryr;
for(int i=0;i<s.size();i++){
if(s[i]>='0'&&s[i]<='9'){
yryr=i;
break;
}else{
l=l*26+s[i]-'A'+1;
}
}
for(int i=yryr;i<s.size();i++){
h=h*10+s[i]-'0';
}
}
//cout<<h<<' '<<l<<'\n';
string str;
if(c==1){
cout<<"R"<<h<<"C"<<l;
return;
}else{
while(l){
str=char((l+25)%26+'A')+str;
if(l%26==0)l--;
l/=26;
}
cout<<str<<h;
return;
}
}
signed main(){
cin>>t;
while(t--){
cin>>str;
if(str[0]=='R'&&str[1]>='0'&&str[1]<='9'){
c=0;
}else{
c=1;
}
zh(c,str);
cout<<'\n';
}
return 0;
}
| ::: |
|---|
| ::::info[CF113C]{open} |
| :::success[正确代码及思路]{open} |
| 我们根据一数学家的定理得知,一质数等于两个数的平方和当且仅当为 |
| ```cpp |
| #include<bits/stdc++.h> |
| using namespace std; |
| int l,r; |
| int ans; |
| bitset<300000005> vis; |
| int main(){ |
| cin>>l>>r; |
| vis[1]=1; |
| for(int i=2;i*i<=r;i++){ |
| if(vis[i]==0){ |
| for(int j=2*i;j<=r;j+=i){ |
| vis[j]=1; |
| } |
| } |
| } |
| for(int i=1;i*4+1<=r;i++){ |
| int j=i*4+1; |
| if(j<l)continue; |
| if(!vis[j])ans++; |
| } |
| if(l<=2&&r>=2)ans++; |
| cout<<ans; |
| return 0; |
| } |
| ``` |
| :::: |