零点工作室暑假集训(AtCoder--ABC259)

A - Growth Record

题意:主人公N岁的时候身高为T,已知他[1,X]期间每年长D,后面不长个子,问M岁的时候他身高多少

思路:0岁的身高是T - X * D,然后在分情况讨论即可

AC代码:

#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 1010;

int n, m, x, t, d;
int a[N], b[N];

int main()
{
    cin >> n >> m >> x >> t >> d;
    if(x <= m) cout <<  t;
    else cout << t - (x - m) * d; 

	return 0;
}

B - Counterclockwise Rotation

题意:在x , y坐标系中,水平向右为x轴正方向,垂直向上为y轴正方向,围绕原点顺时针将点( a , b ))旋转d度,请问新的点的坐标是什么?
思路:可用acos(-1)作为圆周率派的精确值,用hypot(a,b)求斜边长,用atan2(b,a)求边与x轴夹角。最后求出答案

AC代码:

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

int n, t;
double a, b, d, x, y, l, angle;

int main()
{
    cin >> a >> b >> d;
    angle = atan2(b, a);//atan2(a,b)是4象限反正切,它的取值不仅取决于a/b的atan值,还取决于点 (b, a) 落入哪个象限
    angle += d * acos(-1) / 180;//acos(-1); 在数学上就是等于 pi 的值
    l = hypot(a, b);//hypot()函数是cmath标头的库函数,用于查找给定数字的斜边,接受两个数字并返回斜边的计算结果,即sqrt(x * x + y * y) 。
    x = l * cos(angle);
    y = l * sin(angle);
    
    printf("%.20f %.20f",x,y);
}

C - XX to XXX

题意:给定两个串 S和 T,每次可以向 S中相邻且相同的两个字符中间塞一个相同的字符。问若干次操作后 S是否能变成 T
思路:用vector保存两个字符串的信息,相当于将这两个字符串离散成只保存字母和个数信息,然后直接扫一遍源字符串和答案字符串,将连续相同的字母合并即可,再进行对比

AC代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

const int N = 500010;

string s, t, x, y;
vector<int> cs,ct;
int cnt;

int main()
{
    cin >> s >> t;
    s += '0';
    t += '0';
    for (int i = 0; i < s.size() - 1; i ++ ) 
    {
        cnt = 0;
        while (s[i] == s[i + 1]) 
        {
            
            i ++;
            cnt ++;
        }
        x += s[i];
        cs.push_back(cnt + 1);
    }
    for (int i = 0; i < t.size() - 1; i ++ ) 
    {
        cnt = 0;
        while (t[i] == t[i + 1]) 
        {
            
            i ++;
            cnt ++;
        }
        y += t[i];
        ct.push_back(cnt + 1);
    }
    if (x != y) 
    {
        cout << "No";
        return 0;
    }else 
    {
        for (int i = 0; i < cs.size(); i ++ ) 
        {
            if (cs[i] > ct[i] || (cs[i] == 1 && ct[i] > 1)) 
            {
                cout << "No";
                return 0;
            }
        }
        cout << "Yes";
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值