T1

#include<bits/stdc++.h>
using namespace std;

int n;
int a[10], b[10], c[10];
bool to[10];
int ans = 0;
void dfs(int t){
    if(t > n) {
        int sum = 0;
        for(int i = 1; i < n; i++){
            sum ^= b[i] + b[i+1];
        }
        ans = max(ans, sum);
        return ;
    }
    for(int i = 1; i <= n; i++){
        if(to[i]) continue;
        to[i] = 1;
        b[t] = a[i];
        dfs(t+1);
        to[i] = 0;
    }
}
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }

    dfs(1);

    cout << ans;

    return 0;
}

T2

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int n,m,c,a[N][N],s[N][N],x,y,sum=-1e9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>c;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            s[i][j]=a[i][j]+s[i-1][j]+s[i][j-1]-s[i-1][j-1];
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i+c-1][j+c-1]-s[i+c-1][j-1]-s[i-1][j+c-1]+s[i-1][j-1]>sum){
                x=i;
                y=j;
                sum=s[i+c-1][j+c-1]-s[i+c-1][j-1]-s[i-1][j+c-1]+s[i-1][j-1];
            }
        }
    }
    cout<<x<<" "<<y;
    return 0;
}

T3

#include<bits/stdc++.h>
using namespace std;
int a[200007], d[200007], s[200007];
int main(){
	int n, k, q;
	cin >> n >> k >> q;
	for(int i = 1; i <= n; i++){
		int l, r;
		cin >> l >> r;
		d[l]++;
		d[r + 1]--;
	}
	for(int i = 1; i <= 200000; i++){
		a[i] = a[i - 1] + d[i];
		s[i] = s[i - 1];
		if(a[i] >= k){
			s[i]++;
		}
	}
	while(q--){
		int l, r;
		cin >> l >> r;
		cout << s[r] - s[l - 1] << '\n';
	}
	return 0;
}

T4

#include<bits/stdc++.h>
using namespace std;
char a[2001][2001];
int s[2001][2001];
int get(int x,int y,int xx,int yy){
    return s[xx][yy]-s[xx][y-1]-s[x-1][yy]+s[x-1][y-1];
}
int n,m;
bool check(int c){
    int cnt=0;
    for(int i=1;i+c-1<=n;i++){
        for(int j=1;j+c-1<=n;j++){
            if(get(i,j,i+c-1,j+c-1)==0){
                cnt++;
            }
        }
    }
    return cnt>=m;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
            if(a[i][j]=='#')s[i][j]++;
            s[i][j]+=s[i][j-1]+s[i-1][j]-s[i-1][j-1];
        }
    }
    if(n*n-s[n][n]<m){
        cout<<-1;
        return 0;
    }
    if(n*n-s[n][n]==m){
        cout<<1;
        return 0;

    }
    int l=1,r=n*n;
    while(l<r){
        int mid = (l+r+1)/2;
        if(check(mid))l=mid;
        else r=mid-1;
    }
    cout<<l;
    return 0;
}

T5


#include<bits/stdc++.h>
using namespace std;
int a[55][55];
int s[55][55], to[25005];
int f(int x1, int y1, int x2, int y2){
    return s[x2][y2] - s[x1-1][y2] - s[x2][y1-1] + s[x1-1][y1-1];
}
int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cin >> a[i][j];
            s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + a[i][j];
            // cout <<s[i][j] << " ";
        }
    }
    for(int x1 = 1; x1 <= n; x1++){
        for(int y1 = 1; y1 <= n; y1++){
            for(int x2 = x1; x2 <= n; x2++){
                for(int y2 = y1; y2 <= n; y2++){
                    int t = (x2 - x1 + 1) * (y2 - y1 + 1);
                    to[t] = max(to[t], f(x1, y1, x2, y2));
                }
            }
        }
    }
    int q;
    cin >> q;
    for(int i = 1; i <= n*n; i++)   to[i] = max(to[i], to[i-1]);
    while(q--){
        int p;
        cin >> p;
        cout << to[p] << "\n";
    }
    return 0;
}

0 条评论

目前还没有评论...