T1T1

考试错误:无。

思路:

队列模版题,注意用数组模拟即可。

代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1050;
int a[N];
queue<int> q;
int mm[N],hh=0,tt=-1;
signed main(){
	freopen("bd.in","r",stdin);
	freopen("bd.out","w",stdout);
    int m,n;
    cin >> m >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        q.push(a[i]);
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        int w=q.front();
        q.pop();
        bool flag=1;
        for(int i=hh;i<=tt;i++){
            if(mm[i]==w) flag=0;
        }
        if(flag){
            cnt++;
            if(tt-hh+1==m) hh++;
            mm[++tt]=w;
        }
    }
    cout << cnt;
}

T2T2

考试错误:这种题能错吗?

思路:

思路比较简单,只要把每一位加起来,在对3取余就行了。

代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	freopen("three.in","r",stdin);
	freopen("three.out","w",stdout);
    int t;
    cin >> t;
    while(t--){
        int n;
        string s;
        cin >> n;
        getchar();
        getline(cin,s);
        int sum=0;
        for(int i=0;i<s.size();i++){
            if(s[i]>='0'&&s[i]<='9') sum+=s[i]-'0';
        }
        if(sum%3==0) cout << "Yes\n";
        else cout << "No\n";
    }
}

T3T3

考试错误:暴力出奇迹,骗了4040分,没有错误。

思路:

先将所有a[i]a[i]减去xx,在求出最大字段和就可以了。

代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+50;
int a[N],f[N];
signed main(){
    freopen("money.in","r",stdin);
    freopen("money.out","w",stdout);
    int n,x;
    cin >> n >> x;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        a[i]-=x;
        if(f[i-1]<0) f[i]=a[i];
        else f[i]=f[i-1]+a[i];
    }
    int mx=-1;
    for(int i=1;i<=n;i++){
        mx=max(f[i],mx);
    }
    cout << mx;
}

T4T4

考试错误:无。

思路:

表达式求值,没有思路,全是模板。

代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;
stack<int> num;
stack<char> jc;
string s;
bool check(char a,char b){
	int A,B;
	if(a=='+'||a=='-') A=1;
	else if(a=='*'||a=='/') A=2;
	else A=3;
	if(b=='+'||b=='-') B=1;
	else if(b=='*'||b=='/') B=2;
	else B=3;
	return A<=B; 
}
int JS2(int a,int b){
	int r=1;
	while(b){
		if(b%2) r*=a;
		b/=2;
		a*=a;
	}
	return r;
}
void JS(){
	int b=num.top();
    num.pop();
	int a=num.top();
    num.pop();
	char c=jc.top();
    jc.pop();
	int x;
	if(c=='+') x=a+b;
	else if(c=='-') x=a-b;
	else if(c=='*') x=a*b;
	else if(c=='/') x=a/b;
	else x=JS2(a,b);
	num.push(x);
}
void solve(){
    for(int i=0;i<s.size();i++){
        char c=s[i];
        if(isdigit(c)){
            int x=0,z=i;
            while(z<s.size()&&isdigit(s[z])){
				x=x*10+s[z]-'0';
				z++;
			}
			i=z-1;
			num.push(x);
        }else if(c=='('){
            jc.push(c);
        }else if(c==')'){
            while (jc.top()!='(') JS();
			jc.pop();
        }else{
            while(jc.size()&&jc.top()!='('&& check(c,jc.top()))
				JS();
			jc.push(c);
        }
    }while(jc.size()) JS();
    cout << num.top();
}
signed main(){
	freopen("bds.in","r",stdin);
	freopen("bds.out","w",stdout);
    getline(cin,s);
    solve();
}

T5T5

考试错误:只想到了异或是不进位的加法,没想到答案是全异或。

思路:

上文有讲,直接全部异或就行。

代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+50;
int a[N];
signed main(){
    freopen("huiye.in","r",stdin);
    freopen("huiye.out","w",stdout);
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    int sum=a[1];
    for(int i=2;i<=n;i++){
        sum=sum^a[i];
    }
    cout << sum;
}

T6T6

考试错误:这一题不会做,所以没做出来。

思路:

这是一道数学题,只需统计每个数的约数即可。

代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e4+50;
int a[N];
int mx;
unordered_map<int,int> mp;
void get(int b){
    if(b!=1) mp[b]++;
    mp[1]++;
    mx=max(mx,b);
	for(int i=2;i<=b/i;i++){
		if(b%i==0){
			mp[i]++;
		}if(b%i==0&&i!=b/i) mp[b/i]++;
	}
}
signed main(){
    freopen("math2.in","r",stdin);
    freopen("math2.out","w",stdout);
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        int b;
        cin >> b;
        get(b);
    }
    for(int i=1;i<=n;i++){
        for(int j=mx;j>=1;j--){
            if(mp[j]>=i){
                mx=j;
                cout << j << endl;
                break;
            } 
        }
    }
}