Educational Codeforces Round 94 (Rated for Div. 2) String Similarity、RPG Protagonist、Binary String Reconstruction、Zigzags 思维
题目链接:String Similarity
题意:
首先题目定义了两个串的相似(串的构成是0、1),如果两个串存在对于一个下标k,它们的值一样,那么这两个串就相似
然后题目给你一个长度为2n-1的串,我们设下标从1开始,那么[1,n],[2,n+1],[3,n+2]...[n,2n-1]每一个都是一个长度为n的串,你需要找出来长度为n的串,使得这个串和[1,n],[2,n+1],[3,n+2]...[n,2n-1]这些串都相似
题解:
你会发现,只需要输出原长度为2n-1串的下标1,3,5,7....(我们设串的下标从1开始),因为这样输出的话,那么我们构成的这个新串的第i位就和第i个串的第i位相同
代码:

1 #include<stdio.h>
2 #include<string.h>
3 #include<algorithm>
4 #include<iostream>
5 using namespace std;
6 const int maxn=2e3+10;
7 double dp[maxn];
8 int main()
9 {
10 int t;
11 scanf("%d",&t);
12 while(t--)
13 {
14 int n;
15 char s[maxn];
16 scanf("%d",&n);
17 scanf("%s",s);
18 for(int i=0;i<2*n-1;i+=2)
19 {
20 printf("%c",s[i]);
21 }
22 printf("\n");
23 }
24 return 0;
25 }
题目链接:RPG Protagonist
题意:
两个人中一个人可以带p单位的东西,另一个可以带f单位的东西。一共有两种东西,一种物品s1占用s单位空间,这种物品有cnts个;另一种物品w1占用w单位空间,这种物品有cntw个。你需要找出来这两个人一共最多能带出来多少个东西
题解:
我们假设s<w,那么我们肯定是先把s1这个个东西买完之后才会去买w1那个物品。那么对于一个人p,他最多能带走p/s个s1物品,又因为题目要我们要出来这两个人最多能拿出来多少件物品,那么可能p拿走p/s个s1物品就不是最优
我们可以枚举p/s,枚举p拿走多少件s1物品,那么p剩下的空间就去拿w1物品。然后f肯定是拿走剩下的s1物品,然后剩余空间才去拿w1物品
代码:

1 #include<stdio.h>
2 #include<string.h>
3 #include<algorithm>
4 #include<iostream>
5 using namespace std;
6 typedef long long ll;
7 const int maxn=2e3+10;
8 int main()
9 {
10 ll t;
11 scanf("%lld", &t);
12 while (t--)
13 {
14 ll p, f, cnts, cntw, s, w;
15 scanf("%lld%lld",&p,&f);
16 scanf("%lld%lld",&cnts,&cntw);
17 scanf("%lld%lld",&s,&w);
18 ll maxx = min(p / s, cnts), ans = 0;
19 for (ll i = 0; i <= maxx; i++)
20 {
21 //��һ����
22 ll cntss = cnts - i;
23 ll sum=i;
24 ll getw = min(cntw, (p - i * s) / w);
25 ll cntww = cntw;
26 cntww -= getw;
27 sum += getw;
28
29
30 if (s <= w) //�ڶ�����
31 {
32 ll ans = min(cntss, f / s);
33 ll temp = f - ans * s;
34 ll ans2 = min(cntww, temp / w);
35 sum += ans + ans2;
36 }
37 else
38 {
39 ll ans = min(cntww, f / w);
40 ll temp = f - ans * w;
41 ll ans2 = min(cntss, temp / s);
42 sum += ans + ans2;
43 }
44 ans = max(sum, ans);
45 }
46 printf("%lld\n", ans);
47 }
48 return 0;
49 }
50
题目链接:Binary String Reconstruction
题意:
给你一个数组w,由0/1构成,你有一个数组v,对于位置i,如果w[i+x]这个存在且w[i+x]==1,那么v[i]=1
或者对于位置i,如果w[i-x]这个存在且w[i-x]==1,那么v[i]=1
否则,v[i]=0
现在给你v数组,让你求出来w数组并输出,如果w数组不存在输出-1
题解:
先通过v数组中值为0的位置,然后确定w数组的一些位置的值,然后再去判断1。没什么说的,模拟
代码:

1 #include<stdio.h>
2 #include<string.h>
3 #include<algorithm>
4 #include<iostream>
5 using namespace std;
6 typedef long long ll;
7 const int maxn=2e3+10;
8 char s[100010];
9 char w[100010];
10 int main()
11 {
12 ll t;
13 scanf("%lld",&t);
14 while(t--)
15 {
16 ll x;
17 scanf("%s", s);
18 scanf("%lld", &x);
19 ll len=strlen(s);
20 for(ll i=0;i<len+10;++i)
21 w[i]='2';
22 ll flag = 1;
23 for(ll i = 0; i < len; i++)
24 {
25 if (s[i] == '0')
26 {
27 ll temp;
28 temp = i + x;
29 if (temp < len)
30 {
31 w[i + x] = '0';
32 }
33 temp = i - x;
34 if (temp >= 0)
35 {
36 w[i - x] = '0';
37 }
38 }
39 }
40 for(ll i = 0; i < len; i++)
41 {
42 ll pos,flagg=0;
43 if (s[i] == '1')
44 {
45 flagg=0;
46 pos = i + x;
47 if (pos < len)
48 {
49 if (w[i + x] == '1' || w[i + x] == '2')
50 flagg++;
51 }
52 pos = i - x;
53 if(pos >= 0)
54 {
55 if(w[i - x] == '1' || w[i - x] == '2')
56 flagg++;
57 }
58 }
59 else
60 flagg=1;
61 if(!flagg)
62 {
63 flag=0;
64 break;
65 }
66 }
67 if(flag)
68 {
69 for (ll i = 0; i < len; i++)
70 {
71 if (w[i] == '2')
72 printf("1");
73 else printf("%c",w[i]);
74 }
75 printf("\n");
76 }
77 else
78 printf("-1\n");
79 }
80 return 0;
81 }
题目链接:Zigzags
题意:
给你一个长度为n的数组v,你需要找出来i,j,k,l这四个下标,他们要满足v[i]==v[k]且v[j]==v[l]
找出i,j,k,l四元组的四元组的数量输出
题解:
我们可以枚举k,然后k的位置确定了之后我们先记录一下[k+1,n]这些下标对应元素出现数量。然后再去枚举i元素在k之前出现的位置。并进行记录
具体看代码
代码:

1 #include<stdio.h>
2 #include<string.h>
3 #include<algorithm>
4 #include<iostream>
5 using namespace std;
6 typedef long long ll;
7 const int maxn=3e3+10;
8 int v[maxn],num[maxn];
9 int main()
10 {
11 int t;
12 scanf("%d", &t);
13 while (t--)
14 {
15 int n;
16 scanf("%d",&n);
17 for(int i=1;i<=n;++i)
18 {
19 scanf("%d",&v[i]);
20 }
21 int sum=0;
22 for(int i=1;i<=n;++i) //枚举k的位置
23 {
24 int ans=0;
25 memset(num,0,sizeof(num));
26 for(int j=i+1;j<=n;++j)
27 {
28 num[v[j]]++;
29 }
30 for(int j=i-1;j>=1;--j)
31 {
32 if(v[j]==v[i])
33 {
34 sum+=ans;
35 }
36 ans+=num[v[j]];
37 }
38 }
39 printf("%d\n",sum);
40 }
41 return 0;
42 }
Educational Codeforces Round 94 (Rated for Div. 2) String Similarity、RPG Protagonist、Binary String Reconstruction、Zigzags 思维的更多相关文章
- Educational Codeforces Round 94 (Rated for Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1400 A. String Similarity 题意 给出一个长 $2n-1$ 的二进制串 $s$,构造一个长 $n$ 的字 ...
- Educational Codeforces Round 94 (Rated for Div. 2) D. Zigzags (枚举,前缀和)
题意:有一长度为\(n(4\le n\le 3000)\)的数组,选择四个位置\((i,j,k,l)\ (1\le i<j<k\le n)\),使得\(a_i=a_k\)并且\(a_j=a ...
- Educational Codeforces Round 94 (Rated for Div. 2) C. Binary String Reconstruction (构造)
题意:给你一个字符串\(s\),原字符串为\(w\),如果\(i>x\)且\(w_{i-x}=1\),那么\(s_{i}=1\),如果\(i+x\le n\)且\(w_{i+x}=1\),那么\ ...
- Educational Codeforces Round 94 (Rated for Div. 2) B. RPG Protagonist (数学)
题意:你和你的随从去偷剑和战斧,你可以最多可以拿\(p\)重的东西,随从可以拿\(f\)重的东西,总共有\(cnt_{s}\)把剑,\(cnt_{w}\)把战斧,每把剑重\(s\),战斧重\(w\), ...
- Educational Codeforces Round 94 (Rated for Div. 2) A. String Similarity (构造水题)
题意:给你一个长度为\(2*n-1\)的字符串\(s\),让你构造一个长度为\(n\)的字符串,使得构造的字符串中有相同位置的字符等于\(s[1..n],s[2..n+1],...,s[n,2n-1] ...
- Educational Codeforces Round 80 (Rated for Div. 2)E(树状数组,模拟,思维)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],mx[],a[],pos[],sum ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
随机推荐
- Laya 断点调试
Laya 打断点调试并查看堆栈的方法 发现直接加断点不行没办法调试,直接使用这中方法好像可以,选择F5调试 var camera =this.GameScene.getChildByName(&quo ...
- Java基础-数据类型及变量
Java基本语法 1.标识符(zhi) 含义:名字 类名.对象名.方法名.变量名.常量名-- 一个合法的标识符的组成:数字.字母._和$ 注意事项: 不能重复 不能以数字开头 区分大小写 不能以关键字 ...
- leetcode 321. 拼接最大数(单调栈,分治,贪心)
题目链接 https://leetcode-cn.com/problems/create-maximum-number/ 思路: 心都写碎了.... 也许就是不适合吧.... 你是个好人... cla ...
- LeetCode559.N 叉树的最大深度
题目 法一.层序遍历 1 class Solution { 2 public: 3 int maxDepth(Node* root) { 4 if(root== NULL) return 0; 5 q ...
- 使用 TensorBoard 可视化模型、数据和训练
使用 TensorBoard 可视化模型.数据和训练 在 60 Minutes Blitz 中,我们展示了如何加载数据,并把数据送到我们继承 nn.Module 类的模型,在训练数据上训练模型,并在测 ...
- Gulp4.0入门和实战
gulp4.0入门和实战 我最近遇到需要优化web的性能的任务,然后就捣鼓了一些对资源文件优化压缩的方案.由于之前的项目中有使用到gulp,所以在需要处理的web项目中也优先使用这个技术. 先聊聊gu ...
- Java程序入门
编写Java源程序 在d:\day01 目录下新建文本文件,完整的文件名修改为HelloWorld.java ,其中文件名为HelloWorld ,后缀名必须为.java . 用记事本打开 在文件中键 ...
- 探索微软开源Python自动化神器Playwright
相信玩过爬虫的朋友都知道selenium,一个自动化测试的神器工具.写个Python自动化脚本解放双手基本上是常规的操作了,爬虫爬不了的,就用自动化测试凑一凑. 虽然selenium有完备的文档,但也 ...
- win32 修改Edit控件文本颜色与背景色
#define WM_CTLCOLORMSGBOX 0x0132 #define WM_CTLCOLOREDIT 0x0133 //编辑控件Edit #define WM_CTLCOLORLISTBO ...
- JVM虚拟机基础
JVM 全称Java Virtual Machine,也就是我们耳熟能详的Java 虚拟机.它能识别.class 后缀的文件,并且能够解析它的指令,最终调用操作系统上的函数,完成我们想要的操作. Ja ...