一道阿姆斯特朗回旋好题( Convex HDU - 5979)



2001年5月8日,阿姆斯特朗(Armstrong, 1929-2013) 教授发明了一种名为“阿姆斯特朗回旋加速喷气式阿姆斯特朗加密”的加密算法,算法从未公开,直至2013阿姆斯特朗教授逝世后,其生前的研究手稿被其儿子小阿姆斯特朗(Xiaoarmstrong,1995-)发表后才得以被大众所知。一天,小阿姆斯特朗突然对阿姆斯特朗回旋加速喷气式阿姆斯特朗加密算法产生了兴趣,她决定研究一下这个阿姆斯特朗回旋加速喷气式阿姆斯特朗加密算法,但由于阿姆斯特朗回旋加速喷气式阿姆斯特朗加密算法十分复杂,于是小阿姆斯特朗决定今天只研究阿姆斯特朗回旋加速喷气式阿姆斯特朗加密算法的第一步。于是,她找来了一道acm训练题进行了阿姆斯特朗回旋加速喷气式阿姆斯特朗加密,在进行完阿姆斯特朗回旋加速喷气式阿姆斯特朗加密算法的第一步之后,这道题变成了下面这串数字:
 
1746953559 543520353 1886593121 1634296677 1868767340 2019915374 1634235424 1818304628 1869619308 1937010281 1986095136 1752440933 1634934885 1679844717 1635021673 543515502 1864396660 1768384882 1869619310 779382377 544424202 544567161 2003791467 543520544 544104803 544499047 1702043726 1852140903 1629516660 1919251558 1852402720 1735289195 1701344288 1769107232 544106855 1852403568 1851859060 1752440932 1869619301 1937010281 544108320 543516788 1986948963 539916389 1663067479 1629515361 544174956 544499047 1851859022 1936026727 1952801312 1852138871 1667327264 1634738280 1864397417 1752440934 1701716069 1651009385 1931506287 1701668709 779318382 2003783178 1986619168 1870209125 1752440949 1633951845 1629512052 1953853282 1701344288 1735287072 539780460 1634036848 1663067507 1969450081 1702125932 1701344288 1701994784 1718558817 1701344288 1852793632 779642230 1225394734 1414877262 1701336074 1629513074 1830839666 1769237621 543517808 1953719668 1935762208 170816357 543516756 1936877926 1768693876 1663067502 1635020399 544435817 544175988 1702129257 544367975 1851859022 541335652 1768189545 1769234787 1948280686 1847616872 1700949365 1718558834 1701344288 1768910880 544437358 543452769 1768253556 1768169586 1851880563 1948280163 1919885423 1852401513 858267694 540884000 1027350606 741355808 1008742688 541335613 824196412 1409952048 1847616872 544503909 1701734764 1868767347 1767994478 541991022 1702129257 1936876903 1684957472 1952539497 543649385 543516788 1818717793 539915109 543516756 544044403 1948280431 1310745960 1836412448 1936876898 544434464 1635216481 857764729 170799158 1414876938 173299024 544370502 1751343461 1936028704 1633886324 1864394099 1970304117 1852776564 1818632293 544498031 1651340654 544436837 1768189545 1769234787 1948280686 1629513064 543253874 1948280431 1663067496 1702260335 1411395192 1881171304 1953393010 1981834341 1702194273 1752375411 1684829551 1986095136 540221541 1768384868 1629516660 1919251558 1701344288 1667589152 1818324329 1768910880 170816622 0
 
现在,请你来做这道acm训练题,对阿姆斯特朗回旋加速喷气式阿姆斯特朗加密算法不了解的同学请看Hint。
Input

请看题目描述

Output

请看题目描述

Sample Input
4 1
90 90 90 90
6 1
60 60 60 60 60 60
Sample Output
2.000
2.598
Hint
关于阿姆斯特朗回旋加速喷气式阿姆斯特朗加密算法的第一步:
该算法首先读入一段文本,该文本的每个字符仅占1字节,直到结束。
然后,该算法会将连续的每4个字节的二进制位按逆序连接,凑成一个整数,并在末尾加0。例如:
读入:
abcdefgh
(二进制:01100001(a) 01100010(b) 01100011(c) 01100100(d) 01100101(e) 01100110(f) 01100111(g) 01101000(h))
转换后:
1684234849 1751606885 0
(二进制:01100100011000110110001001100001 01101000011001110110011001100101 0)
(01100100(d)01100011(c)01100010(b)01100001(a) 01101000(h)01100111(g)01100110(f)01100101(e) 0)

首先你要解密这个密码得到题目,每个大数字是由四个字母的二进制倒着排列得到的总的二进制又换算成了整数,所以第一种方法对于输入的一个数字a,a%256得到后八位二进制的十进制值,然后转成字符型输出,然后在移动八位继续输出,直到这个数移完位置,继续输入新的数字重复操作,代码如下

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
    long long a;
    while(cin >> a){
        while(a){
            cout << (char)(a%256);
            a = a >> 8;
        }
    }
    return 0;
}
方法二则巧妙的运用了数组储存的特性,因为对于一个大数,在一个数组中它的二进制就是倒着存放的,那么转成字符输出时,恰好就正过来了,所以直接输入整个数组,把数组转成字符串类型char*,输出就可以解密密码

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[10000];
int main(){
    int cnt,i;
    i = 0;
    while(cin >> a[i]){
        if(!a[i])break;
        i++;
    }
    cout << (char*)a << endl;
    return 0;
}
截图:


所以这个题目是这样的

Convex


We have a special convex that all points have the same distance to origin point.
As you know we can get N segments after linking the origin point and the points on the convex. We can also get N angles between each pair of the neighbor segments.
Now give you the data about the angle, please calculate the area of the convex

Input
There are multiple test cases.
The first line contains two integer N and D indicating the number of the points and their distance to origin. (3 <= N <= 10, 1 <= D <= 10)
The next lines contain N integers indicating the angles. The sum of the N numbers is always 360.
Output
For each test case output one float numbers indicating the area of the convex. The printed values should have 3 digits after the decimal point.
Sample Input
4 1
90 90 90 90
6 1
60 60 60 60 60 60
Sample Output
2.000
2.598
题目说每一个segment是这个点和原点相连并且这个点和相邻点相连的面积,所以这是求三角形面积,最后求和就可以

其中角度换算成弧度,度数*π/180

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define pi 3.1415926
int main(){
    int n;
    double d;
    while(cin >> n >> d){
        double sum = 0.0;
        double degree;
        int i;
        for(i = 0; i < n; i++){
            cin >> degree;
            sum += 0.5*d*d*sin(degree*pi/180.0);//求面积,相加
        }
        printf("%.3f\n",sum);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值