The Mountain

All as we know, a mountain is a large landform that stretches above the surrounding land in a limited area. If we as the tourists take a picture of a distant mountain and print it out, the image on the surface of paper will be in the shape of a particular polygon.

From mathematics angle we can describe the range of the mountain in the picture as a list of distinct points, denoted by (x_1,y_1)(x  1 ​  ,y  1 ​  ) to (x_n,y_n)(x  n ​  ,y  n ​  ). The first point is at the original point of the coordinate system and the last point is lying on the xx-axis. All points else have positive y coordinates and incremental xx coordinates. Specifically, all x coordinates satisfy 0 = x_1 < x_2 < x_3 < ... < x_n0=x  1 ​  <x  2 ​  <x  3 ​  <...<x  n ​  . All yy coordinates are positive except the first and the last points whose yy coordinates are zeroes.

The range of the mountain is the polygon whose boundary passes through points (x_1,y_1)(x  1 ​  ,y  1 ​  ) to (x_n,y_n)(x  n ​  ,y  n ​  ) in turn and goes back to the first point. In this problem, your task is to calculate the area of the range of a mountain in the picture.

Input  

The input has several test cases and the first line describes an integer t (1 \le t \le 20)t(1≤t≤20) which is the total number of cases.  In each case, the first line provides the integer n (1 \le n \le 100)n(1≤n≤100) which is the number of points used to describe the range of a mountain. Following nn lines describe all points and the ii-th line contains two integers x_ix  i ​   and y_i (0 \le x_i, y_i \le 1000)y  i ​  (0≤x  i ​  ,y  i ​  ≤1000) indicating the coordinate of the ii-th point.

样例输入  3 3 0 0 1 1 2 0 4 0 0 5 10 10 15 15 0 5 0 0 3 7 7 2 9 10 13 0

样例输出  

1.000000

125.000000

60.500000 

比赛的题目只能写写水题(也蛮开心的),这题大意就是在笛卡尔坐标系里面画一个折线图求所占面积,没有什么特别的就输入一个计算一下与前面点连接占的面积,主要就是加上一个三角形面积后加的矩形面积要根据于前一点的高低比较得来。

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    while(n--){
        int m,x,y,bx = 0,by = 0,flag = 1;
        double ans = 0;
        cin >> m;
        while(m--){
            cin >> x >> y;
            if(flag){
             	flag = 0;
            	continue;   
            }
            ans += (x - bx)*abs(y - by)*1.0/2.0;
            if(y >= by && by != 0){
                ans += (x - bx)*by*1.0;
            }
            if(y < by && y > 0){    
                ans += (x - bx)*y*1.0;
            }
            bx = x, by = y;
        }
        printf("%.6f\n",ans);
    }
    return 0;
}

 

export interface Question { word: string; //单词 sentence: string; //例句 options: string[]; //选项 answer: string; //答案 } //题库 export const questionData: Question[] = [ { word: "book", options: ["书籍", "笔", "橡⽪", "背包"], answer: "书籍", sentence: "I love to read a good book every night." }, { word: "computer", options: ["电视", "电脑", "⼿机", "相机"], answer: "电脑", sentence: "I use the computer for work and entertainment." }, { word: "apple", options: ["⾹蕉", "桃⼦", "梨", "苹果"], answer: "苹果", sentence: "She enjoys eating a crisp apple in the afternoon." }, { word: "sun", options: ["⽉亮", "太阳", "星星", "地球"], answer: "太阳", sentence: "The sun provides warmth and light to our planet." }, { word: "water", options: ["⽕", "⼟地", "⻛", "⽔"], answer: "⽔", sentence: "I always carry a bottle of water with me." }, { word: "mountain", options: ["沙漠", "海洋", "平原", "⼭"], answer: "⼭", sentence: "The mountain range is covered in snow during winter." Question.ets ArkTS 16 }, { word: "flower", options: ["树⽊", "草地", "花", "灌⽊"], answer: "花", sentence: "The garden is filled with colorful flowers." }, { word: "car", options: ["⾃⾏⻋", "⻜机", "船", "汽⻋"], answer: "汽⻋", sentence: "I drive my car to work every day." }, { word: "time", options: ["空间", "时钟", "⽇历", "时间"], answer: "时间", sentence: "Time flies when you're having fun." }, { word: "music", options: ["画", "舞蹈", "⾳乐", "戏剧"], answer: "⾳乐", sentence: "Listening to music helps me relax." }, { word: "rain", options: ["雪", "雷电", "阳光", "⾬"], answer: "⾬", sentence: "I enjoy the sound of rain tapping on the window." }, { word: "fire", options: ["冰", "⽕焰", "烟雾", "闪电"], answer: "⽕焰", sentence: "The campfire warmed us on a chilly evening." }, { word: "friend", options: ["陌⽣⼈", "邻居", "家⼈", "朋友"], answer: "朋友", sentence: "A true friend is always there for you." }, { word: "food", options: ["⽔果", "蔬菜", "⾁", "⻝物"], answer: "⻝物", 17 sentence: "Healthy food is essential for a balanced diet." }, { word: "color", options: ["⿊⾊", "⽩⾊", "红⾊", "颜⾊"], answer: "颜⾊", sentence: "The artist used a vibrant color palette." }, { word: "bookshelf", options: ["椅⼦", "桌⼦", "书架", "床"], answer: "书架", sentence: "The bookshelf is filled with novels and reference books." }, { word: "moon", options: ["太阳", "星星", "⽉亮", "地球"], answer: "⽉亮", sentence: "The moonlight illuminated the night sky." }, { word: "school", options: ["公园", "商店", "医院", "学校"], answer: "学校", sentence: "Students go to school to learn and grow." }, { word: "shoes", options: ["帽⼦", "⾐服", "裤⼦", "鞋⼦"], answer: "鞋⼦", sentence: "She bought a new pair of stylish shoes." }, { word: "camera", options: ["电视", "电脑", "相机", "⼿机"], answer: "相机", sentence: "The photographer captured the moment with his camera." } ] //从题库中随机抽取n个题⽬ export function getRandomQuestions(count: number) { let length = questionData.length; let indexes: number[] = []; while (indexes.length < count) { let index = Math.floor(Math.random() * length); if (!indexes.includes(index)) { indexes.push(index) } } return indexes.map(index => questionData[index]) } 报错Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals) <ArkTSCheck> Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals) <ArkTSCheck> 应为'(', ',' 或 '}',得到'Question'
03-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值