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< ...
随机推荐
- oracle坚决不挂01(表,索引,视图的创建,修改,删除,查询)
考试快来了,来篇oracle干货,复习一下(挣扎一下) 废话不多说,开始写! 这篇是数据库对象的有关操作的总结! 数据库对象有熟悉的表,视图,索引,序列,同义词等(这个oracle东西真不少,小声bb ...
- IDEA一步步创建Maven管理的Spring入门程序
目前,做Java开发的很多人都在使用IDEA了,而有些人也选择用Eclipse,我这里介绍一下IDEA一步步创建Maven项目的步骤,并创建一个Spring的入门程序(Java项目,非Web项目),讲 ...
- 十八:SQL注入之堆叠及绕WAF
堆叠查询注入 (双查询注入) stacked injections(堆叠注入)从名词的含义就可以看到是一堆的SQL语句一起执行,而在真实的运用中也是这样的,我们知道在mysql中,主要是命令行中,每一 ...
- windows下使用mingw和msvc静态编译Qt5.15.xx
windows下使用mingw和msvc静态编译Qt5.15.xx 下载并安装相关依赖软件 Python version 2.7 https://www.python.org/downloads/ ( ...
- Pycharm同时执行多个脚本文件
Pycharm同时执行多个脚本文件 设置Pycharm使它可以同时执行多个程序 打开Pycharm 找到Run,点击确认 点击Edit Configurations 右上角Allow parallel ...
- kubernets与API服务器进行交互
一 为何需要与kubernets集群的API服务器进行交互 1.1 kubernets提供了一种downapi的资源可以将pod的元数据渲染成环境变量或者downward卷的形式挂载到容器的文件系 ...
- leetcode 1593. 拆分字符串使唯一子字符串的数目最大(DFS,剪枝)
题目链接 leetcode 1593. 拆分字符串使唯一子字符串的数目最大 题意: 给你一个字符串 s ,请你拆分该字符串,并返回拆分后唯一子字符串的最大数目. 字符串 s 拆分后可以得到若干 非空子 ...
- STM32F207时钟系统解析
在前几天的文章<晶振原理解析>中介绍了晶振如何产生时钟的,板子使用的是25M无源晶振,下文将介绍STM32F207的时钟系统如何将25M晶振时钟转换为120M系统主频时钟的. 01.时钟系 ...
- python(paramiko模块的简单使用)
#通过paramiko模块连接主机运行bash命令 import paramiko hostname = '192.168.88.31' port = 22 username = 'root' pas ...
- Django Full Coverage
Django(个人推荐, 如果项目较大 需要协同开发, 建议使用django这种重量级框架, 如果类似于纯api的后端应用建议使用 flask, 轻量小巧 , 麻雀虽小五脏俱全) 1.Django是什 ...