codeforces#710

A题
A
思路:根据矩阵大小和给定的数字x找到他的坐标,然后计算新的数字就可以;

#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        ll n,m;
        cin>>n>>m;
        ll x;
        cin>>x;
        ll a=x/n;
        ll b=x%n;
        if(b) a++;
        else b=n;
        b--;
        ll y=b*m+a;
        cout<<y<<endl;
    }
    return 0;
}

B
==思路:先把所有的*的下标找出来,然后用指针找就好;

#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int t;
	cin >> t;
	while (t--){
		int n, k;
		cin >> n >> k;
		string s;
		cin >> s;
		
		vector<int> pos;
		for (int i = 0; i < n; ++i){
			if (s[i] == '*') pos.push_back(i);
		}
		
		int ans = 1;
		int p = 0;
		for (int i = 1; i < pos.size(); ++i){
			if (i == pos.size()-1 or pos[i+1] - pos[p] > k){
				ans++;
				p = i;
			}
		}
		cout << ans <<endl;
	}
	return 0;
}

C

思路:最长连续公共子序列,由于数据范围很小,可以暴力做
也可以使用dp,

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
const int N=50;
char a[N],b[N];
int f[N][N];
int solve(char a[],char b[]){
    int n=strlen(a+1),m=strlen(b+1);
    int res=0;
    for(int i=1;i<=n;i++){
        
        for(int j=1;j<=m;j++){
            if(a[i]==b[j]) f[i][j]=f[i-1][j-1]+1;
            else f[i][j]=0;
            res=max(res,f[i][j]);   
        } 
    }
    return res;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        memset(f,0,sizeof f);
        scanf("%s%s",a+1,b+1);//不要学我cin跟scanf混用,容易t,QwQ
        int n=strlen(a+1),m=strlen(b+1);
        cout<<n+m-(solve(a,b)*2)<<endl;
    }
    return 0;
}
/*
5
a
a
abcd
bc
hello
codeforces
hello
helo
dhjakjsnasjhfksafasd
adjsnasjhfksvdafdser
*/

D

#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
#define x first
#define y second
const int N=1e6+10;
int a;
int V[N];

void solve(){
    int t=0;
    int n;
    map<int,int> m;//map遍历比unordered_map更快
    // vector<int>V;//尽量少用vector数据一大容易t;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a),m[a]++;
    for(auto i:m){
        V[++t]=i.y;
    }
    sort(V+1,V+t+1);
    int res=0;
    if(m.size()==1) printf("%d\n",V[1]);
    else if(m.size()==2) printf("%d\n",V[2]-V[1]);
    else{
        for(int i=1;i<=t-1;i++) res+=V[i];
        if(res<V[t]) printf("%d\n",V[t]-res);
        else {
            if((res+V[t])%2==0) printf("%d\n",0);
            else printf("%d\n",1);
        }

    }
    

}
int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }


    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值