The 14th Jilin Provincial Collegiate Programming Contest部分题解(A,B,C,E,F,G,H,J,L,M)

oj: CodeForces
2020/1/31 训练赛

Problem A.Chord

题解

签到题,根据题目判断一下就行(注意是环)

代码

#include <bits/stdc++.h>
#define PI atan(1.0)*4
#define rp(i,s,t) for (register int i = (s); i <= (t); i++)
#define RP(i,t,s) for (register int i = (t); i >= (s); i--)
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define m_p make_pair
#define p_b push_back
#define ins insert
#define era erase
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define dg if(debug)
#define pY puts("YES")
#define pN puts("NO")
#define outval(a) cout << "Debuging...|" << #a << ": " << a << "\n";
#define outval2(a,b) cout << "Debuging...|" << #a << ": " << a <<"\t"<< #b << ": " << b << "\n";
#define outval3(a,b,c) cout << "Debuging...|" << #a << ": " << a <<"\t"<< #b << ": " << b <<"\t"<< #c << ": " << c << "\n";
using namespace std;
int debug = 0;
ll gcd(ll a,ll b){
   
   
	return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b){
   
   
	return a/gcd(a,b)*b;
}
inline int read(){
   
   
	int s=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
   
   
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
   
   
		s=s*10+ch-'0';
		ch=getchar();
	}
	return s*f;
}
const int N = 1e5+7;
string s[20]={
   
   "C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
void solve(){
   
   
	string a,b,c;cin>>a>>b>>c;
	int id1,id2,id3;
	rp(i,0,11) if(s[i]==a) id1=i;
	rp(i,0,11) if(s[i]==b) id2=i;
	rp(i,0,11) if(s[i]==c) id3=i;
	// outval3(id1,id2,id3);
	if((id2-id1+12)%12==4&&(id3-id2+12)%12==3) puts("Major triad");
	else if((id2-id1+12)%12==3&&(id3-id2+12)%12==4) puts("Minor triad");
	else puts("Dissonance");
}
int main(){
   
   
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef ONLINE_JUDGE
#else
	freopen("in.txt", "r", stdin);
	//debug = 1;
#endif
	//time_t beg, end;
	//if(debug) beg = clock();

	int T;cin>>T;
	while(T--) solve();

	/*
	if(debug) {
		end = clock();
		printf("time:%.2fs\n", 1.0 * (end - beg) / CLOCKS_PER_SEC);
	}
	*/
	return 0;
}

Problem B.Problem Select

题解

签到题,逆序取一下数字,然后排序输出取前k小数就行了

代码

#include <bits/stdc++.h>
#define PI atan(1.0)*4
#define rp(i,s,t) for (register int i = (s); i <= (t); i++)
#define RP(i,t,s) for (register int i = (t); i >= (s); i--)
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define m_p make_pair
#define p_b push_back
#define ins insert
#define era erase
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define dg if(debug)
#define pY puts("YES")
#define pN puts("NO")
#define outval(a) cout << "Debuging...|" << #a << ": " << a << "\n";
#define outval2(a,b) cout << "Debuging...|" << #a << ": " << a <<"\t"<< #b << ": " << b << "\n";
#define outval3(a,b,c) cout << "Debuging...|" << #a << ": " << a <<"\t"<< #b << ": " << b <<"\t"<< #c << ": " << c << "\n";
using namespace std;
int debug = 0;
ll gcd(ll a,ll b){
   
   
	return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b){
   
   
	return a/gcd(a,b)*b;
}
inline int read(){
   
   
	int s=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
   
   
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
   
   
		s=s*10+ch-'0';
		ch=getchar();
	}
	return s*f;
}
const int N = 1e5+7;
void solve(){
   
   
	int n,k;cin>>n>>k;
	vector<int> v;v.clear();
	rp(i,1,n){
   
   
		string s;cin>>s;
		// outval(s);
		int len=s.size();
		int id;
		rp(j,0,len-1) if(s[j]=='/') id=j;
		// outval(id);
		int num=0;
		rp(j,id+1,len-1) num=num*10+s[j]-'0';
		// outval(num);
		v.p_b(num);
	}
	sort(v.begin(),v.end());
	rp(i,0,k-1) {
   
   
		printf("%d%s",v[i],i==k-1?"\n":" ");
	}
}
int main(){
   
   
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef ONLINE_JUDGE
#else
	freopen("in.txt", "r", stdin);
	//debug = 1;
#endif
	//time_t beg, end;
	//if(debug) beg = clock();

	int T;cin>>T;
	while(T--) solve();

	/*
	if(debug) {
		end = clock();
		printf("time:%.2fs\n", 1.0 * (end - beg) / CLOCKS_PER_SEC);
	}
	*/
	return 0;
}

Problem C. String Game(dp)

oj: CodeForces

题意

给你一个 s s s 串和 t t t 串,求出 s s s 中有多少和 t t t 相同的子序列。

题解

定义 d p [ i ] [ j ] dp[i][j] dp[i][j] 表示 s [ : i ] s[:i] s[:i] 中有多少个和 t [ : j ] t[:j] t[:j] 相同的子序列。

由于 s [ : i ] s[:i] s[:i] 包含 s [ : i − 1 ] s[:i-1] s[:i1] ,所以 d p [ i ] [ j ] dp[i][j] dp[i][j] 包含 d p [ i − 1 ] [ j ] dp[i-1][j] dp[i1][j]

s [ i ] = = t [ j ] s[i] == t[j] s[i]==t[j] 时, d p [ i ] [ j ] dp[i][j] dp[i][j] 又包含 d p [ i − 1 ] [ j − 1 ] dp[i-1][j-1] dp[i1][j1] ,所以有:

边界:

dp[i][0] = dp[i - 1][0] + (s[i] == t[0])

转移:

dp[i][j] += dp[i - 1][j];
if(s[i] == t[j]) dp[i][j] += dp[i - 1][j - 1];

代码

#include <bits/stdc++.h>
#define _for(i, a) for(int i = 0, lennn = (a); i < lennn; ++i)
#define _rep(i, a, b) for(int i = (a), lennn = (b); i <= lennn; ++i)
using namespace std;
typedef long long LL;
const int maxn = 5005;
const int mod = 1000000007;

inline int read() {
   
   
    int x(0), f(1); char ch(getchar());
    while (ch<'0' || ch>'9') {
   
    if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0'&&ch <= '9') {
   
    x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}

LL dp[5005][1005];
char s[maxn], t[maxn];
int n, m;

void init() {
   
   
    n = strlen(s), m = strlen(t);
    _for(i, n) _for(j, m) dp[i][j] = 0;
}

void sol() {
   
   
    init();
    _for(i, n) {
   
   
        if(i) dp[i][0] += dp[i - 1][0];
        if(s[i] == t[0]) {
   
   
            ++dp[i][0];
        }
        dp[i][0] %= mod;
    }
    for(int i = 1; i < n; ++i) {
   
   
        for(int j = 1; j < m; ++j) {
   
   
            dp[i][j] += dp[i - 1][j];
            if(s[i] == t[j]) dp[i][j] += dp[i - 1][j - 1];
            dp[i][j] %= mod;
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值