uva 11170 - Cos(NA)
来源:互联网 发布:html5 仿淘宝个人主页 编辑:程序博客网 时间:2024/04/30 15:04
Problem F
Cos(NA)
Input: Standard Input
Output: Standard Output
Have you ever looked at formulae of the form Cos(NA)? If you haven’t looked at them yet, just look at them now:
These formulae will make you believe that any Cos(NA) can be expanded in an expression which contains only one function Cos(A) and all the coefficients are also integers. In this problem your job is to find such a formula for Cos(NA) given the value of N.
Input
The input file contains at most 50 lines of inputs. Each line contains a positive integer N (N<50). Input is terminated by a line containing a single zero.
Output
For each line of input except the last one you should produce one line of output. This line should contain the formula (As described in the problem statment) for Cos(NA). You don’t need to print any redundant things in the output such as (a) Printing operators in two consecutive places (b) Printing the exponent when it is 1 (c) Printing the coefficient when it is 1 (d) Just look at the output for sample input for details.
Sample Input Output for Sample Input
2
3
4
0
2Cos^2(A)-1
4Cos^3(A)-3Cos(A)
8Cos^4(A)-8Cos^2(A)+1
Problem setter: Shahriar Manzoor
Moderator: Derek Kisman
输出cos函数的展开式,找到递推式,然后注意些细节。
暑假集训就这么开始了啊!
#include<cstdio>#include<cstring>#include<queue>#include<vector>#include<iostream>#include<algorithm>using namespace std;typedef long long LL;const int INF = 1000000000;const int maxn = 50 + 5;LL ans[maxn][maxn];void pre(){ memset(ans, 0, sizeof(ans)); for(int i = 0;i < maxn;i++){ if(i%4 == 0) ans[0][i] = 1; else if(i%4 == 2) ans[0][i] = -1; else ans[0][i] = 0; } ans[1][1] = 1; for(int i = 1;i < maxn;i++){ for(int j = 2;j < maxn;j++){ ans[i][j] = 2*ans[i-1][j-1] - ans[i][j-2]; } }}int main(){ pre(); int n; while(scanf("%d", &n)){ if(n == 0) break; int tag = 1; for(int i = n;i > 0;i--){ if(ans[i][n] != 0){ if(tag == 1){ tag = 0; } else{ if(ans[i][n] > 0) printf("+"); else printf("-"); } if(ans[i][n] != 1) printf("%lld", abs(ans[i][n])); printf("Cos"); if(i != 1) printf("^%d", i); printf("(A)"); } } if(ans[0][n] > 0) printf("+%lld", ans[0][n]); else if(ans[0][n] < 0) printf("%lld", ans[0][n]); printf("\n"); } return 0;}
- uva 11170 - Cos(NA)
- na
- NA
- NA
- UVA 12437 Kisu Pari Na 2
- UVA 12575 Sin Cos Problem
- COS
- cos
- cos
- NA心得
- R语言 na.fail和na.omit
- na lab1 AC了......
- NA(P)T
- na很郁闷
- Farewell, Li Na
- Kisu Pari Na 2
- NA 和 NULL
- NA主要课程内容
- IOS瀑布流 通过自定义UICollectionViewController的Layout布局实现
- 内存的5个分区
- Median in Stream
- TCP状态转换图(state transition diagram)
- bitcoin.conf
- uva 11170 - Cos(NA)
- cocos2d-x3.0开发笔记 物理引擎封装Physics深入学习
- 聚类应用 crap
- discuz!主题列表页显示每个帖子的版块名
- C语言必掌握知识点
- (终端,板子...)Linux下模拟CPU/内存占用工具打包发布+使用说明-cpuup&memup
- Oracle中如何插入特殊字符: & 和 ' (多种解决方案)
- java中StringBuffer浅谈
- c语言面试题