【第二学期点三周学习记录】

养成游戏

在这里插入图片描述
在这里插入图片描述

思路

1.这道题用dfs;具有多少层是由有多少个属性决定的;每个底下有多少选项是由K来决定的()

代码

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

const int N=105;
int n,m,k;
int ii[N],jj[N],op[N],a[N],b[N],d[N],v[N];
int vis[N];
int maxx=0LL;

void dfs(int u)
{
	if(u==n+1){
		int ans=0;
		for(int i=1;i<=m;i++){
			if(op[i]==1){
				if(a[i]*vis[ii[i]]+b[i]*vis[jj[i]]>=d[i])	ans+=v[i];
			}
			else{
				if(a[i]*vis[ii[i]]+b[i]*vis[jj[i]]<=d[i])	ans+=v[i];
			}
		}
		maxx=max(maxx,ans);
		return ;
	}
	for(int i=0;i<=k;i++){
		vis[u]=i;
		dfs(u+1);
	}
}

signed main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=m;i++){
		cin>>ii[i]>>jj[i]>>op[i]>>a[i]>>b[i]>>d[i]>>v[i];
	}
	dfs(1);
	cout<<maxx<<endl;
	return 0;
} 

CF2078A Final Verdict

题目描述

Testify - void (Mournfinale) feat. 星熊南巫

You are given an array $ a $ of length $ n $ , and must perform the following operation until the length of $ a $ becomes $ 1 $ .

Choose a positive integer $ k < |a| $ such that $ \frac{|a|}{k} $ is an integer. Split $ a $ into $ k $ subsequences $ ^{\text{∗}} $ $ s_1, s_2, \ldots, s_k $ such that:

  • Each element of $ a $ belongs to exactly one subsequence.
  • The length of every subsequence is equal.

After this, replace $ a = \left[ \operatorname{avg}(s_1), \operatorname{avg}(s_2), \ldots, \operatorname{avg}(s_k) \right] $ , where $ \operatorname{avg}(s) = \frac{\sum_{i = 1}^{|s|} s_i}{|s|} $ is the average of all the values in the subsequence. For example, $ \operatorname{avg}([1, 2, 1, 1]) = \frac{5}{4} = 1.25 $ .

Your task is to determine whether there exists a sequence of operations such that after all operations, $ a = [x] $ .

$ ^{\text{∗}} $ A sequence $ x $ is a subsequence of a sequence $ y $ if $ x $ can be obtained from $ y $ by the deletion of several (possibly, zero or all) elements.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 500 $ ). The description of the test cases follows.

The first line of each test case contains two integers $ n $ , $ x $ ( $ 1 \leq n, x \leq 100 $ ) — the length of the array $ a $ and the final desired value.

The second line contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 1 \leq a_i \leq 100 $ ) — the array $ a $ .

输出格式

For each test case, output “YES’” (without quotes) if there exists such a sequence of operations, and “NO” (without quotes) otherwise.

You can output “YES” and “NO” in any case (for example, strings “yES”, “yes” and “Yes” will be recognized as a positive response).

输入输出样例 #1

输入 #1

4
1 3
3
4 9
7 11 2 5
6 9
1 9 14 12 10 8
10 10
10 10 10 10 10 10 10 10 10 10

输出 #1

YES
NO
YES
YES

说明/提示

In the first test case, $ x = 3 $ and $ a = [3] $ already holds.

In the second test case, $ x = 9 $ , and there exists no sequence of operations such that after all operations, $ a = [9] $ .

In the third test case, $ x = 9 $ , and here is one possible sequence of operations.

  1. $ k = 2 $ , $ s_1 = [1, 12, 8] $ and $ s_2 = [9, 14, 10] $ . Hence, $ a = [\operatorname{avg}(s_1), \operatorname{avg}(s_2)] = [7, 11] $ .
  2. $ k = 1 $ and $ s_1 = [7, 11] $ . Hence, $ a = [\operatorname{avg}(s_1)] = [9] $ .

In the fourth test case, $ x = 10 $ , and here is one possible sequence of operations.

  1. $ k = 1 $ and $ s_1 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] $ . Hence, $ a = [\operatorname{avg}(s_1)] = [10] $ .

思路

  • 一个小小的重点,如果他要分的话,每一组分的数都要是一样的;所以答案就是它的平均数()QAQ()

代码

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

int main()
{
	int t;cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		int a[n+4],s=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];s+=a[i];
		}
		if((double)s/n*1.0==(double)m)	cout<<"YES"<<endl;
		else	cout<<"NO"<<endl;
	}
	return 0;
}

AT_abc310_b [ABC310B] Strictly Superior

题目描述

题意简述

商店有 N N N 个产品。第 i i i 个产品的价格为 P i P_i Pi ,并且有 C i C_i Ci 个功能。这些功能的数值不超过 M M M

在这里,如果满足以下条件,则称产品 i i i “绝对优越” 于产品 j j j

  • P i ≥ P j P_i \ge P_j PiPj
  • 产品 i i i 的所有功能产品 j j j 都有。
  • P i > P j P_i > P_j Pi>Pj ,或者产品 j j j 有至少一个功能是产品 i i i 所没有的。

请你计算是否存在一个产品 “绝对优越” 于另一个产品。

输入格式

第一行有两个整数: N , M N,M N,M

接下来 N N N 行,每行第一个整数为 P i P_i Pi ,第二个整数为 C i C_i Ci 。后面 C i C_i Ci 个整数为 F i , j F_{i,j} Fi,j ,表示第 i i i 个产品的第 j j j 个功能。

输出格式

如果有 “绝对优越” 的产品,输出 Y e s Yes Yes 。否则输出 N o No No

输入输出样例 #1

输入 #1

5 6
10000 2 1 3
15000 3 1 2 4
30000 3 1 3 5
35000 2 1 5
100000 6 1 2 3 4 5 6

输出 #1

Yes

输入输出样例 #2

输入 #2

4 4
3 1 1
3 1 2
3 1 2
4 2 2 3

输出 #2

No

输入输出样例 #3

输入 #3

20 10
72036 3 3 4 9
7716 4 1 2 3 6
54093 5 1 6 7 8 10
25517 7 3 4 5 6 7 9 10
96930 8 2 3 4 6 7 8 9 10
47774 6 2 4 5 6 7 9
36959 5 1 3 4 5 8
46622 7 1 2 3 5 6 8 10
34315 9 1 3 4 5 6 7 8 9 10
54129 7 1 3 4 6 7 8 9
4274 5 2 4 7 9 10
16578 5 2 3 6 7 9
61809 4 1 2 4 5
1659 5 3 5 6 9 10
59183 5 1 2 3 4 9
22186 4 3 5 6 8
98282 4 1 4 7 10
72865 8 1 2 3 4 6 8 9 10
33796 6 1 3 5 7 9 10
74670 4 1 2 6 8

输出 #3

Yes

说明/提示

  • 2 ≤ N ≤ 100 2 \le N \le 100 2N100
  • 1 ≤ M ≤ 100 1 \le M \le 100 1M100
  • 1 ≤ P i ≤ 1 0 5 ( 1 ≤ i ≤ N ) 1 \le P_i \le 10^5 (1 \le i \le N) 1Pi105(1iN)
  • 1 ≤ C i ≤ M ( 1 ≤ i ≤ N ) 1 \le C_i \le M (1 \le i \le N) 1CiM(1iN)
  • 1 ≤ F i , 1 < F i , 2 < . . . < F i , C i ≤ M ( 1 ≤ i ≤ N ) 1 \le F_{i,1} < F_{i,2} < ... < F_{i,C_i} \le M(1 \le i \le N) 1Fi,1<Fi,2<...<Fi,CiM(1iN)

思路

  1. 我以为会是很麻烦的()结果是二维数组存一下就好了QAQ();

代码

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

const int N=105;
int p[105],o[N][N];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		int c;
		cin>>p[i]>>c;
		for(int j=1;j<=c;j++){
			int t;
			cin>>t;
			o[i][t]=1;
		}
	}
	int ans=0;
	//始终判断j是不是比i更优() 
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==j)	continue;
			int f=0,cnt=0;
			for(int k=1;k<=m;k++){
				if(o[i][k]==1&&o[j][k]==0){
					f=1;break;
				}
				else if(o[j][k]==1&&o[i][k]==0){
					cnt++;
				}
			}
			if(f==0){
				if(p[j]<p[i])	ans++;
				else if(p[j]==p[i]&&cnt>0)	ans++;
			}
		}
	}
	if(ans>0)	cout<<"Yes";
	else	cout<<"No";
	return 0;
}

AT_abc310_c [ABC310C] Reversible

题目描述

ボールがいくつか刺さった棒が $ N $ 本あり、各ボールには英小文字が $ 1 $ 個書かれています。

$ i\ =\ 1,\ 2,\ \ldots,\ N $ について、$ i $ 番目の棒に刺さった各ボールの英小文字は、文字列 $ S_i $ によって表されます。 具体的には、$ i $ 番目の棒には文字列 $ S_i $ の長さ $ |S_i| $ に等しい個数のボールが刺さっており、 刺さっているボールの英小文字を、棒のある端から順に並べたものは文字列 $ S_i $ と等しいです。

$ 2 $ つの棒は、一方の棒に刺さっているボールの英小文字をどちらかの端から並べた列と、もう一方の棒に刺さっているボールの英小文字をどちらかの端から並べた列が一致するとき、同じ棒とみなされます。 より形式的には、$ 1 $ 以上 $ N $ 以下の整数 $ i,\ j $ について、$ i $ 本目の棒と $ j $ 本目の棒は、$ S_i $ が $ S_j $ と一致するか、$ S_i $ が $ S_j $ を前後反転したものと一致するとき、かつそのときに限り、同じとみなされます。

$ N $ 本の棒の中に、何種類の異なる棒があるかを出力してください。

输入格式

入力は以下の形式で標準入力から与えられる。

$ N $ $ S_1 $ $ S_2 $ $ \vdots $ $ S_N $

输出格式

答えを出力せよ。

输入输出样例 #1

输入 #1

6
a
abc
de
cba
de
abc

输出 #1

3

说明/提示

制約

  • $ N $ は整数
  • $ 2\ \leq\ N\ \leq\ 2\ \times\ 10^5 $
  • $ S_i $ は英小文字のみからなる文字列
  • $ |S_i|\ \geq\ 1 $
  • $ \sum_{i\ =\ 1}N |S_i| \leq 2 \times 105 $

Sample Explanation 1

- $ S_2 $ = abc が $ S_4 $ = cba を前後反転したものと一致するため、$ 2 $ 番目の棒と $ 4 $ 番目の棒は同じとみなされます。 - $ S_2 $ = abc が $ S_6 $ = abc と一致するため、$ 2 $ 番目の棒と $ 6 $ 番目の棒は同じとみなされます。 - $ S_3 $ = de が $ S_5 $ = de と一致するため、$ 3 $ 番目の棒と $ 5 $ 番目の棒は同じとみなされます。 よって、$ 6 $ 本の棒の中に、$ 1 $ 本目の棒、$ 2 $ 本目の棒( $ 4,\ 6 $ 本目の棒と同じ)、$ 3 $ 本目の棒( $ 5 $ 本目の棒と同じ)の $ 3 $ 種類の異なる棒があります。

思路

  • 可以直接用reverse函数()好耶()

代码

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

const int N=2e5+10;
set<string> ss;
signed main()
{
	int n,ans=0;
	cin>>n;
	int f=0;
	string s;
	for(int i=1;i<=n;i++){
		cin>>s;
		if(ss.count(s)==0)	ans++;
		ss.insert(s);
		reverse(s.begin(),s.end());
		ss.insert(s);

	}
	cout<<ans;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值