本文主要是介绍ural 1149. Sinus Dances dfs,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1149. Sinus Dances
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Let An = sin(1–sin(2+sin(3–sin(4+…sin( n))…)
Let Sn = (…( A 1+ n) A 2+ n–1) A 3+…+2) An+1
For given N print SN
Let Sn = (…( A 1+ n) A 2+ n–1) A 3+…+2) An+1
For given N print SN
Input
One integer N. 1 ≤ N ≤ 200
Output
Line containing SN
Sample
input | output |
---|---|
3 | ((sin(1)+3)sin(1–sin(2))+2)sin(1–sin(2+sin(3)))+1 |
Problem Author: Vladimir Gladkov
Problem Source: Ural Collegiate Programming Contest, April 2001, Perm, Test Round
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.StringTokenizer;public class Main {public static void main(String[] args) {new Task().solve();}
}class Task {InputReader in = new InputReader(System.in);PrintWriter out = new PrintWriter(System.out);String A(int step , int n){if(step == n){return "sin("+n+")" ;}return "sin(" + step + ((step%2==1)?"-":"+") + A(step+1 ,n) + ")" ;}String A(int n){return A(1 , n) ;}String S(int step , int n){if(step == n){return "sin(1)+" + n + "" ;}return "(" + S(step+1 , n) + ")" + A(n+1-step) + "+" + step ;}String S(int n){return S(1 , n) ;}void solve() {out.println(S(in.nextInt())) ;out.flush() ;}
}class InputReader {public BufferedReader reader;public StringTokenizer tokenizer;public InputReader(InputStream stream) {reader = new BufferedReader(new InputStreamReader(stream), 32768);tokenizer = new StringTokenizer("");}private void eat(String s) {tokenizer = new StringTokenizer(s);}public String nextLine() {try {return reader.readLine();} catch (Exception e) {return null;} }public boolean hasNext() {while (!tokenizer.hasMoreTokens()) {String s = nextLine();if (s == null)return false;eat(s);}return true;}public String next() {hasNext();return tokenizer.nextToken();}public int nextInt() {return Integer.parseInt(next());}public int[] nextInts(int n) {int[] nums = new int[n];for (int i = 0; i < n; i++) {nums[i] = nextInt();}return nums;}public long nextLong() {return Long.parseLong(next());}public double nextDouble() {return Double.parseDouble(next());}public BigInteger nextBigInteger() {return new BigInteger(next());}}
这篇关于ural 1149. Sinus Dances dfs的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!