福建工程学院第七届ACM程序设计新生赛

版权声明:转就转吧~~记得声明噢~~ https://blog.csdn.net/Soul_97/article/details/84931459

感觉被打出翔一样的难受。。。(没AK)

https://ac.nowcoder.com/acm/contest/289#question

A换算一下即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e4 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;

int main()
{
    int T;
    cin >> T;
    int sta_ = 1;
    while(T --){
        int h1,h2,m1,m2,s1,s2;
        cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;
        int c1 = h1*3600 + m1*60 + s1;
        int c2 = h2*3600 + m2*60 + s2;
        int ans;
        if(c2 <= c1){
            ans = 86400 - c1 + c2;
        }else{
            ans = c2 - c1;
        }
        printf("Case #%d: %d\n",sta_,ans);
        sta_ ++;
    }
    return 0;
}

B水

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e4 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;

int main()
{
    double a,b;
    while(cin >> a >> b){
        printf("%.2f\n",a*a/2);
    }
    return 0;
}

C开始以为还要线段树写?

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e4 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
int a[N],b[N];
int main()
{
    int n,l,r;
    cin >> n >> l >> r;
    for(int i = 1;i <= n;i ++)
        cin >> a[i];
    for(int i = 1;i <= n;i ++)
        cin >> b[i];
    int cnt = 0;
    for(int i = l;i <= r;i ++){
        if(a[i] <= l && b[i] >= r)
            cnt ++;
    }
    cout << cnt;
    return 0;
}

D贴个板子

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e6 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
class Vector2d
{
public:
    double x_;
    double y_;

public:
    Vector2d(double x, double y):x_(x), y_(y){}
    Vector2d():x_(0), y_(0){}

    //二维向量叉乘, 叉乘的结果其实是向量,方向垂直于两个向量组成的平面,这里我们只需要其大小和方向
    double CrossProduct(const Vector2d vec)
    {
        return x_*vec.y_ - y_*vec.x_;
    }

    //二维向量点积
    double DotProduct(const Vector2d vec)
    {
        return x_ * vec.x_ + y_ * vec.y_;
    }

    //二维向量减法
    Vector2d Minus(const Vector2d vec) const
    {
        return Vector2d(x_ - vec.x_, y_ - vec.y_);
    }

    //判断点M,N是否在直线AB的同一侧
    static bool IsPointAtSameSideOfLine(const Vector2d &pointM, const Vector2d &pointN,
                                        const Vector2d &pointA, const Vector2d &pointB)
    {
        Vector2d AB = pointB.Minus(pointA);
        Vector2d AM = pointM.Minus(pointA);
        Vector2d AN = pointN.Minus(pointA);

        //等于0时表示某个点在直线上
        return AB.CrossProduct(AM) * AB.CrossProduct(AN) >= 0;
    }
};

//三角形类
class Triangle
{
private:
    Vector2d pointA_, pointB_, pointC_;

public:
    Triangle(Vector2d point1, Vector2d point2, Vector2d point3)
        :pointA_(point1), pointB_(point2), pointC_(point3)
    {
        //todo 判断三点是否共线
    }

    //计算三角形面积
    double ComputeTriangleArea()
    {
        //依据两个向量的叉乘来计算,可参考http://blog.csdn.net/zxj1988/article/details/6260576
        Vector2d AB = pointB_.Minus(pointA_);
        Vector2d BC = pointC_.Minus(pointB_);
        return fabs(AB.CrossProduct(BC) / 2.0);
    }

    bool IsPointInTriangle1(const Vector2d pointP)
    {
        double area_ABC = ComputeTriangleArea();
        double area_PAB = Triangle(pointP, pointA_, pointB_).ComputeTriangleArea();
        double area_PAC = Triangle(pointP, pointA_, pointC_).ComputeTriangleArea();
        double area_PBC = Triangle(pointP, pointB_, pointC_).ComputeTriangleArea();

        if(fabs(area_PAB + area_PBC + area_PAC - area_ABC) < 0.000001)
            return true;
        else return false;
    }

    bool IsPointInTriangle2(const Vector2d pointP)
    {
        return Vector2d::IsPointAtSameSideOfLine(pointP, pointA_, pointB_, pointC_) &&
            Vector2d::IsPointAtSameSideOfLine(pointP, pointB_, pointA_, pointC_) &&
            Vector2d::IsPointAtSameSideOfLine(pointP, pointC_, pointA_, pointB_);
    }

    bool IsPointInTriangle3(const Vector2d pointP)
    {
        Vector2d AB = pointB_.Minus(pointA_);
        Vector2d AC = pointC_.Minus(pointA_);
        Vector2d AP = pointP.Minus(pointA_);
        double dot_ac_ac = AC.DotProduct(AC);
        double dot_ac_ab = AC.DotProduct(AB);
        double dot_ac_ap = AC.DotProduct(AP);
        double dot_ab_ab = AB.DotProduct(AB);
        double dot_ab_ap = AB.DotProduct(AP);

        double tmp = 1.0 / (dot_ac_ac * dot_ab_ab - dot_ac_ab * dot_ac_ab);

        double u = (dot_ab_ab * dot_ac_ap - dot_ac_ab * dot_ab_ap) * tmp;
        if(u < 0 || u > 1)
            return false;
        double v = (dot_ac_ac * dot_ab_ap - dot_ac_ab * dot_ac_ap) * tmp;
        if(v < 0 || v > 1)
            return false;

        return u + v <= 1;
    }

    bool IsPointInTriangle4(const Vector2d pointP)
    {
        Vector2d PA = pointA_.Minus(pointP);
        Vector2d PB = pointB_.Minus(pointP);
        Vector2d PC = pointC_.Minus(pointP);
        double t1 = PA.CrossProduct(PB);
        double t2 = PB.CrossProduct(PC);
        double t3 = PC.CrossProduct(PA);
        return t1*t2 >= 0 && t1*t3 >= 0;
    }
};


int main()
{
    int x1,x2,x3,y1,y2,y3,x,y;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >>y3 >>x >>y;
    Triangle tri(Vector2d(x1,y1), Vector2d(x2,y2), Vector2d(x3,y3));
         Vector2d point(x,y);
    bool flag = tri.IsPointInTriangle4(point);
    if(flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

E看清题,是先分配在询问  

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e6 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
struct node{
    ll id,need;
    node(ll _id,ll _need){
        id = _id;
        need = _need;
    }
};
vector<node> v;
ll r[N];
ll n,m,q;
int main()
{
    while(cin >> n >> m >> q){
        v.clear();
        memset(r,0,sizeof(r));
        ll id,need;
        for(ll i = 1;i <= n;i ++)
            cin >> r[i];
        for(ll i = 1;i <= m;i ++){
            cin >> id >> need;
            v.push_back(node(id,need));
        }

        for(int i = 0;i < v.size();i ++){
            if(r[v[i].id] >= v[i].need){
                r[v[i].id] -= v[i].need;
                v[i].need = 0;
            }else{
                v[i].need -= r[v[i].id];
                r[v[i].id] = 0;
            }
        }

        while(q --){
            ll p;
            cin >> p;
            p -= 1;

            if(v[p].need)
                cout << v[p].need << endl;
            else
                cout << "Yes" << endl;
        }
    }
    return 0;
}

F 1e8的数据 直接暴力

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
int p[N];
int main()
{
    int n,m,q;
    scanf("%d%d",&n,&m);
    for(int i = 1;i <= m;i ++){
        scanf("%d",&p[i]);
    }
    scanf("%d",&q);
    while(q --){
        int t;
        scanf("%d",&t);
        int ans = 1000000000;
        for(int i = 1;i <= m;i ++){
            ans = min(ans,abs(t-p[i]));
        }
        printf("%d\n",ans);
    }
}

G 没做出来

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
const int N = 1e5 + 5;
char c, s[N], clo[N];
 
int p[N];
 
int main()
{
    int T;
    scanf("%d", &T);
    while(T--) {
        scanf(" %c %s", &c, s + 1);
        int cnt = 0, now = 1;
        int n = strlen(s + 1);
        s[0] = 'A';
        for(int i = 2; i <= n; i++) {
            if(s[i] != s[i-1]) {
                p[++cnt] = now;
                now = 1;
                clo[cnt] = s[i-1];
            }
            else now++;
        }
 
        if(now) p[++cnt] = now, clo[cnt] = s[n];
       /* for(int i = 1; i <= cnt; i++) {
            cout << clo[i] << " ";
        }
        cout << endl;*/
        if(cnt%2 == 1) {
            int flag = 0;
            if(!(p[cnt/2+1] >= 2 && clo[cnt/2+1] == c))  flag = 1;
            if(!flag) {
                for(int i = 1; i <= cnt/2; i++) {
                    if(p[i] + p[cnt-i+1] < 3 || clo[i] != clo[cnt-i+1]) {
                        flag = 1;
                        break;
                    }
                }
            }
            if(!flag) puts("yes");
            else puts("no");
        }
        else puts("no");
    }
    return 0;
}

H画个图推一下

#include "bits/stdc++.h"
using namespace std;
char s[100004];
int main()
{
    long long x,y;
    while(cin>>x>>y)
    {
        long long a;
        cin>>a;
        if(x==0&&y==0)
        {
            if(a!=0)puts("You are lying");
            else puts("We are together");
            continue;
        }
        if((abs(x)+abs(y))&1){
            puts("Not the fate");
            continue;
        }
        long long base=min(abs(x),abs(y));
        base+=abs(abs(x)-abs(y));
        if(a<base||(a-base)&1)puts("You are lying");
        else puts("We are together");
    }
}

I 记录所有字母的个数  从头开始输出  即是字典序最小

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e4 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
int c[27];
int main()
{
    string s;
    int k;
    while(cin >> k >> s){
        memset(c,0,sizeof(c));
        for(int i = 0;i < s.size();i ++){
            c[s[i]-'a'] ++;
        }
        bool flag = true;

        for(int i = 0;i < 27;i ++){
            if(c[i]){
                if(c[i]%k!=0){
                    flag = false;
                    break;
                }
            }
        }
        if(flag){

                for(int p = 1;p <= k;p ++){
                    for(int i = 0;i < 27;i ++){
                    if(c[i]){
                        for(int j = 1;j <= c[i]/k;j ++){
                            cout << (char)(i+'a');
                        }
                    }
                }
                }

            cout << endl;
        }else{
            cout << -1 << endl;
        }

    }
    return 0;
}

J  字符串给强推了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
ll change1(string s)
{
    ll ans = 0;
    for(int i = 0;i < s.size();i ++){
        ans *= 10;
        ans += (s[i]-'0');
    }
    return ans;
}
string change2(ll a)
{
    string s = "";
    while(a){
        s += (a%10+'0');
        a /= 10;
    }
    reverse(s.begin(),s.end());
    return s;
}
int main()
{
    string up,down;
    ll n,k;
    while(cin >> up >> k){

        k = change1(up) - k;
        string t = change2(k);
        down = "";
        for(int i = 1;i <= up.size() - t.size();i ++)
            down += '0';
        down += t;
        int cnt = 0;
        string ans = "";
        //cout << up << endl << down << endl;
        for(int i = 0;i < up.size();i ++){
            cnt ++;
            if(up[i] != down[i]){
                    ans += up[i];
                break;
            }else{
                 ans += down[i];
            }
        }
        for(int i = 1;i <= up.size()-cnt;i ++)
            ans += '9';
        if(ans <= up){
            int pos;
            for(int i = 0;i < ans.size();i ++){
                if(ans[i] != '0'){
                    pos = i;
                    break;
                }
            }
            for(int i = pos;i < ans.size();i ++){
                cout << ans[i];
            }
        }else{
            for(int i = up[cnt-1]-'0';i >= down[cnt-1]-'0';i --){
                ans[cnt-1] = (char)(i+'0');
                if(ans <= up)
                    break;
            }
            int pos;
            for(int i = 0;i < ans.size();i ++){
                if(ans[i] != '0'){
                    pos = i;
                    break;
                }
            }
            for(int i = pos;i < ans.size();i ++){
                cout << ans[i];
            }
        }

        cout << endl;
    }
    return 0;
}

K 如果 xy同时扩大m倍之后  k在扩大后的区间内  则可以

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;

int main()
{
    int T;
    cin >> T;
    while(T --){
        int n,x,y;
        cin >> n >> x >> y;

        if(n < x)
            cout << "N" << endl;
        else if(n >= x && n <= y)
            cout << "Y" << endl;
        else{
            int t;
            if(n % y == 0)
                t = n / y;
            else
                t = n / y + 1;
            if(n >= x*t && n <= y*t)
                cout << "Y" << endl;
            else
                cout << "N" << endl;
        }
    }
}

猜你喜欢

转载自blog.csdn.net/Soul_97/article/details/84931459