CCF第三十一次计算机软件能力认证202309-1坐标变换(其二) (暴力求解法,80分)

代码如下

此算法是暴力求解算法,时间复杂度O(mn),只能得80分,而且代码在模拟系统里一直提交错误(评判系统应该有bug),但在本地可以正常运行*

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct Operation {
    /*操作结点*/
    int type;
    double value;
} Operation;

typedef struct Point{
    /*查询结点*/
    int idx1;
    int idx2;
    double x;
    double y;
} Point;

void output(Operation* ops, Point* points, int m);

int main() {
    int n, m;
    scanf("%d %d", &n, &m);

    Operation* ops = (Operation*)malloc(sizeof(Operation) * n);
    for (int i = 0; i < n; i++) {
        /*输入n个操作*/
        scanf("%d %lf", &(ops[i].type), &(ops[i].value));
    }

    Point* points = (Point*)malloc(sizeof(Point) * m);
    for (int i = 0; i < m; i++) {
        /*输入m个查询*/
        scanf("%d %d %lf %lf", &(points[i].idx1), &(points[i].idx2), &(points[i].x), &(points[i].y));
    }

    output(ops, points, m);

    free(ops);
    free(points);
    return 0;
}

void output(Operation* ops, Point* points, int m) {
    for (int i = 0; i < m; i++) {
        Point *ptr = &(points[i]);
        for (int j = ptr->idx1; j <= ptr->idx2; j++) {
            double v = ops[j - 1].value;
            if (ops[j - 1].type == 1) {
                ptr->x *= v;
                ptr->y *= v;
            } else {
                double temp1 = ptr->x, temp2 = ptr->y;
                ptr->x = temp1 * cos(v) - temp2 * sin(v);
                ptr->y = temp1 * sin(v) + temp2 * cos(v);
            }
        }
        printf("%.3lf %.3lf\n", ptr->x, ptr->y);
    }
}

输入

10 5
2 0.59
2 4.956
1 0.997
1 1.364
1 1.242
1 0.82
2 2.824
1 0.716
2 0.178
2 4.094
1 6 -953188 -946637
1 9 969538 848081
4 7 -114758 522223
1 9 -535079 601597
8 8 159430 -511187

输出

-1858706.758 -83259.993
-1261428.460 201113.678
-75099.123 -738950.159
-119179.897 -789457.532
114151.880 -366009.892

程序运行结果

posted @ 2023-09-28 15:02  Guanjie255  阅读(324)  评论(0编辑  收藏  举报