2020吉林省ICPC

The 14th Jilin Provincial Collegiate Programming Contest

题目连接:https://codeforces.com/gym/102800

Problem A. Chord
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
思路:这个题其实不难,就是把琴键都存入到一个二维数组中,根据输入的琴键,查找其所在位置(即下标),最后计算差值即可。

题解

#include<bits/stdc++.h>
using namespace std;
char a[12][5] = {{"C"},{"C#"},{"D"},{"D#"},{"E"},{"F"},{"F#"},{"G"},{"G#"},{"A"},{"A#"},{"B"}},b[2];
int t,c[5],m,n;

int main(){
	cin >> t;
	while(t--){
		for(int i=0;i<3;i++){
			cin >> b;
			for(int j=0;j<12;j++){
				if(strcmp(b,a[j])==0) {
					c[i] = j;
					break;
				}
			}
		}
		if(c[1]-c[0]<0)m=12+c[1]-c[0];
		else m = c[1]-c[0];
		if(c[2]-c[1]<0)n=12+c[2]-c[1];
		else n = c[2]-c[1];
		if(m==4&&n==3)cout <<"Major triad" << endl;
		else if(m==3&&n==4)cout <<"Minor triad" << endl;	
		else cout << "Dissonance" << endl;
	}
	return 0;
}

其中,注意存入的字符型二维数组
①每行元素用 { } ;
②每行元素其实是一个字符串,所以用 “ ” 引用。

Problem B. Problem Select

在这里插入图片描述思路:只要得到字符串结尾的数字,并将其存入到整形数组中,最后排序输出即可。

题解

#include<bits/stdc++.h>
using namespace std;
#define N 1001
int t,n,k,x,b[N];
char a[N];

int main(){
	cin >> t;
	while(t--){
		cin >> n >> k;
		for(int i=0;i<n;i++){
			cin >> a;
			int j=0; 
			while(!(a[j]>47&&a[j]<58))j++;
			x = a[j] - '0';
			while(a[++j]){
				x = x*10 + (a[j]-'0');
			}
			b[i] = x;
		}
		sort(b,b+n);
		for(int i=0;i<k;i++){
			cout << b[i] << " ";
		}	
		cout << endl;
	}
	return 0;
}

Problem C. String Game
在这里插入图片描述
思路:自己尝试动手做了这道题,但做完后,发现思路其实不正确,看题解,发现用的是DP,

题解

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
string s,t;
ll dp[5005][5005];
const int mod=1e9+7;
int main(){
    while(cin>>s>>t){
        int n=s.size(),m=t.size();
        for(int i=0;i<=n;i++)dp[0][i]=1;
        for(int j=1;j<=m;j++)
        for(int i=1;i<=n;i++){
            dp[j][i]=0;
        }
        for(int i=1;i<=m;i++){
            for(int j=1;j<=n;j++){
                dp[i][j]=dp[i][j-1];
                if(t[i-1]==s[j-1]){
                    dp[i][j]+=dp[i-1][j-1];
                }
                dp[i][j]%=mod;
            }
        }
        cout<<dp[m][n]<<endl;
    }
}

Problem E. Shorten the Array

在这里插入图片描述
Problem L. Swimmer

在这里插入图片描述
题解

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
typedef long long ll;
int x[N];
int n,m,q;
int p,k;
int main(){
        cin>>n>>m>>q;
        for(int i=1;i<=n;i++)scanf("%d",&x[i]);
        while(q--){
                scanf("%d%d",&p,&k);
                ll l=1LL*p*x[k];
                if (l<=m){
                        printf("%lld\n",l);
                        continue;
                }else{
                        ll t=l/m;
                        if (t&1){
                                printf("%lld\n",1LL*m-(l-m*t));
                        }else{
                                printf("%lld\n",l-m*t);
                        }
                }
        }
}

其他没有写的题解 ,参考此处

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值