生活随笔
收集整理的這篇文章主要介紹了
一道阿姆斯特朗回旋好题( Convex HDU - 5979)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?? 一道阿姆斯特朗回旋好題 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;
}
總結
以上是生活随笔 為你收集整理的一道阿姆斯特朗回旋好题( Convex HDU - 5979) 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。