A - A Count Task
反思:一起做的,一开始误打误撞讨论出了正确的思路和方向,但是因为全队对于子串的定义过于模糊,也没有注意到很关键的“连续的点”,因此一直兜兜转转也没有A,要长个记性啦~
子串:串中任意个连续的字符组成的子序列称为该串的字串。
!!!注意:该字符串本身也是他的一个子串
思路:遍历该字符串,如果当前字符与下一个字符是连续相等的就使指针后移并且记录当前的字符连续相等的数量,如果不是相等的就break掉。记录完一组连续相等的字符个数,就计算这些个字符所能组成的字符串个数,即n*(n+1)/2
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PII pair<int, int>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define pi acos(-1)
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int main()
{
int t;
cin>>t;
while(t--)
{
string a;
cin>>a;
int n=a.size();
ll res=0;
for(int i=0;i<n;i++)
{
ll cnt=1;
while(i+1<n)
{
if(a[i]==a[i+1])
{
i++;
cnt++;
}
else break;
}
res+=(cnt+1)*cnt/2;
}
cout<<res<<endl;
}
return 0;
}
E - A Hard Allocation
反思:签到题,一开始过于浮躁了,读题没读清楚,情况没分好wa了一发。本身读题和思考水平不高的情况下应该慎重一点,减少罚时。
ps:果然xy老师的表头就是长
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define off ios::sync_with_stdio(false);
#define INF 0x3f3f3f3f
#define forn (i, n) for (int i = 0; i < int(n); i++)
#define scan1(n) scanf("%d", &n)
#define scan2(n, m) scanf("%d %d", &n, &m)
#define scan3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define debug(x) cout << '*' << x << endl
#define pb(x, y) x.push_back(y)
// 1s == 1e7 ~ 1e8
const int N = 2010;
const int M = 200010;
const int mod = 1e9 + 7;
const int P = 131;
const double esp = 1e-6;
typedef pair<int, int> PII;
typedef long long ll;
typedef vector<int> vic;
int main() {
off;
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
if (m == 1 || n % m == 0)
cout << 0 << endl;
else
cout << 1 << endl;
}
return 0;
}
G - Flower
反思:这题一开始是xy老师做的,当时我们俩在做H那道题也卡了很长时间,过了之后来帮xy老师思考这道题的时候明显状态都不对劲了,hhhh中间讨论的时候还莫名其妙笑了一段时间,下次要好好跟上xy老师分析的步伐
思路:题目中说的是可以保持其中一朵花的高度不变,令其他所有花的高度同时减一,为了保证修剪的次数最少,我们可以先对花朵的高度进行从小到大的排序。修剪的时候秉持着从大到小修剪使他们逐渐趋于一致的原则,一共n朵花,针对较小的第n-1朵花可以保持不变,修剪第n朵花来使二者一致。计算的过程中需要注意,每次作为高度较小的那朵花保持不变,那么下一次作为较小的那朵花与他之间的差值应该在原本的差值基础上加上这次修剪的高度,因此我们需要设置一个pre量来计算之前修剪的次数,最后比较最矮一朵花与总修剪量之间的高度就可以啦~
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PII pair<int, int>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define pi acos(-1)
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int a[N];
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n,i;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
sort(a, a + n);
int res = 0;
int pre = 0;
for (i = n - 1; i > 1; i--)
//最后一次修剪倒数第二矮的花时我们是保持最后一朵花不变的
//因此后续与最后一朵花高度的比较也不需要有这一次的修剪量
{
res += a[i] - a[i - 1] + pre;
pre += a[i] - a[i - 1];
// cout << res << ' ' << pre << endl;
}
if (a[0] < res + 1)
cout << -1 << endl;
else
cout << res + a[i] - a[i - 1] + pre << endl;
//与最后一朵花比较时不需要计算最后一次的修剪量,但是最终输出的修剪量需要加上(补题的时候出错了
}
return 0;
}
H - Overflow
反思:物理题啦,和物理公式关系比较多,当时俺敲得,在cincout超时了,最后换成了scanf和printf就过了,所以以后还是不用cin cout了(
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PII pair<int, int>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define pi acos(-1)
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
double w[N], p[N];
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
scanf("%d", &n);
double res = 0;
for (int i = 0; i < n; i++)
scanf("%lf%lf", &w[i], &p[i]);
double s, h, v;
scanf("%lf%lf%lf", &s, &h, &v);
for (int i = 0; i < n; i++)
{
if (p[i] > 1)
{
res += pow(w[i], 3) / s;
}
else
{
res += p[i] * pow(w[i], 3) / s;
}
}
if (v / s + res > h)
printf("%.2lf\n", h);
else
printf("%.2lf\n", res + v / s);
}
return 0;
}
J - The puzzle
反思:这题一开始xg老师的思路是将所有的情况分成存在相互对称(即第一个数是4,而第四个数是1)和完全乱序的情况,不停的debug之后发现还是wa 赛后才发现有环的思想存在 所以事实证明还是要多做题多补题
思路:这里所给的数字的乱序一定是多次任意两个数字之间的交换所形成的,最直接的来想,我们确认了当前位置的数字,以及这个数字应该在的位置现在对应的数字,这样就会形成一个环,而不在这个环内的数字就是已经在自己应该在的位置上了;而需要交换的次数也就是环的交点-1
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PII pair<int, int>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define pi acos(-1)
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int a[N];
bool str[N];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,ans=0;
scanf("%d",&n);
memset(str,0,sizeof str);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
{
int t=a[i];
int res=0;
while(!str[t])
{
str[t]=1;
res++;
t=a[t];
}
if(res) ans+=res-1;
}
printf("%d\n",ans);
}
return 0;
}
总体总结
1.首先此次组队赛整体来说前期状态不够好,但是后来也能保持积极思考追上来实在是很棒啦~当然对于被带飞的我本人而言,除了坚定了要积极思考锻炼思维能力以及代码实现能力的想法之外,也感受到队友的鼓励和帮助,对于跟上各位老师的思维以及提供一点帮助的进步真是让我感到很高兴呢~
2.读题实在是太重要啦 好多次因为读题的失误浪费了时间,针对长的题面也要耐下心来读
3.tle往往就是因为cin cout 或许下一次还是直接用scanf和printf比较好
4.不能停下学习的脚步呀 菜菜~