A.
代码语言:javascript复制//A
#include <bits/stdc .h>
using namespace std;
int main()
{
int n,x,y;
string s;
scanf("%d %d %d",&n,&x,&y);
cin>>s;
int ans=0;
for(int i=n-x;i<n;i ){
if(s[i]=='1'&&i!=n-y-1){
s[i] = '0';
ans ;
}else if(s[i]=='0'&&i==n-y-1){
s[i]='1';ans ;
}
}
//cout<<s<<" "<<ans<<endl;
cout<<ans<<endl;
return 0;
}
B.简单排序,然后for扫一遍,我用vector时间复杂度高了
代码语言:javascript复制//B
#include <bits/stdc .h>
using namespace std;
#define ll long long
#define rep(i,x,y) for(int i=x;i<=y;i )
#define per(i,x,y) for(int i=y;i<=x;i )
const int N = 2e5 10;
vector<int> a;
int book[N];
int main()
{
int n;
scanf("%d",&n);
rep(i,1,n){
int t;
scanf("%d",&t);
a.push_back(t);
}
sort(a.begin(),a.end());
int ans = 0;
rep(i,1,n){
int tp = lower_bound(a.begin(),a.end(),i) - a.begin();
if(tp==a.size()){//所有元素都小于i
break;
}else {
a.erase(a.begin() tp);
ans = i;
}
}
printf("%dn",ans);
return 0;
}
C.
有两个相同的就取其中一个,然后要考虑取其中一个对后面奇偶位的影响
代码语言:javascript复制//C
#include <bits/stdc .h>
using namespace std;
#define ll long long
#define rep(i,x,y) for(int i=x;i<=y;i )
#define per(i,x,y) for(int i=y;i<=x;i )
const int N = 2e5 10;
char s[N];
char ts[N];
int n,cnt,ans;
int check(){
for(int i=1;i<=n;i =2){
if((i&1)&&s[i]==s[i 1]){
return 0;
}
}
return 1;
}
void solve(){
cnt = 0;
int flag = 0;
for(int i=1;i<=n;i ,flag^=1){
if(s[i]==s[i 1]&&flag==0){
ans ;
flag^=1;//删除产生的影响
continue;
}
ts[ cnt] = s[i];
}
rep(i,1,cnt)s[i] = ts[i];
n = cnt;
}
int main()
{
scanf("%d",&n);
getchar();
rep(i,1,n){
scanf("%c",&s[i]);
}
if(check()&&n%2==0){
printf("0n");
printf("%s",s 1);
return 0;
}
ans = 0;
while(check()==0){
solve();
}
if(n%2==1){
ans ; n--;
}
printf("%dn",ans);
rep(i,1,n)printf("%c",s[i]);
return 0;
}
D.
我真是个弟弟。
给你n个数,这n个数是x的所有因子(除了1和x),若存在,则把n个数排序,任何对称的两个数之积就是,
就从1到n/2判断,a[i]*a[n-i 1] == a[1]*a[n] ,有一个不满足就-1.
都符合再看全不全,你把这个ans验证一下,找ans所有因子,数量减2不等于n就是错的。
代码语言:javascript复制#include <bits/stdc .h>
using namespace std;
#define ll long long
int is[1000005];
ll a[1000005];
void getP() {
is[0] = 1;
is[1] = 1;
is[2] = 0;
for(int i=2; i<=1000005; i ) {
if(!is[i]) {
for(int j = i i; j<=1000005; j =i) {
is[j] = 1;
}
}
}
}
int judge(ll ans){
ll num = 1;
for(ll i = 2;i*i<=ans;i ){
if(ans%i==0){
ll at = 0;
while(ans%i==0){
ans/=i;
at ;
}
num=num*(at 1);
}
}
if(ans>1)num*=2;
return num;
}
int main() {
ll t,n,mi,mx,ans;
getP();
cin.tie(0);
cin>>t;
while(t--) {
cin>>n;
cin>>a[0];
mi = a[0];
mx = a[0];
if(n==1) {
if(!is[a[0]]) {
ans=a[0]*a[0];
} else ans = -1;
} else {
for(int i=1; i<=n-1; i ) {
cin>>a[i];
}
sort(a,a n);
ans = a[0]*a[n-1];
for(int i=0;i<n/2;i ){
if(a[i]*a[n-1-i]==ans);
else {
ans = -1;
break;
}
}
if(n%2==1&&a[n/2]*a[n/2]!=ans)ans = -1;
if(judge(ans)-2!=n)ans = -1;
}
cout<<ans<<endl;
}
return 0;
}