ural 1149. Sinus Dances dfs

2024-09-09 06:58
文章标签 dfs ural dances 1149 sinus

本文主要是介绍ural 1149. Sinus Dances dfs,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1149. Sinus Dances

Time limit: 1.0 second
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

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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1150476

相关文章

hdu 2489 (dfs枚举 + prim)

题意: 对于一棵顶点和边都有权值的树,使用下面的等式来计算Ratio 给定一个n 个顶点的完全图及它所有顶点和边的权值,找到一个该图含有m 个顶点的子图,并且让这个子图的Ratio 值在所有m 个顶点的树中最小。 解析: 因为数据量不大,先用dfs枚举搭配出m个子节点,算出点和,然后套个prim算出边和,每次比较大小即可。 dfs没有写好,A的老泪纵横。 错在把index在d

poj 3050 dfs + set的妙用

题意: 给一个5x5的矩阵,求由多少个由连续6个元素组成的不一样的字符的个数。 解析: dfs + set去重搞定。 代码: #include <iostream>#include <cstdio>#include <set>#include <cstdlib>#include <algorithm>#include <cstring>#include <cm

ural 1297. Palindrome dp

1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unli

ural 1820. Ural Steaks 贪心

1820. Ural Steaks Time limit: 0.5 second Memory limit: 64 MB After the personal contest, happy but hungry programmers dropped into the restaurant “Ural Steaks” and ordered  n specialty steaks

ural 1017. Staircases DP

1017. Staircases Time limit: 1.0 second Memory limit: 64 MB One curious child has a set of  N little bricks (5 ≤  N ≤ 500). From these bricks he builds different staircases. Staircase consist

ural 1026. Questions and Answers 查询

1026. Questions and Answers Time limit: 2.0 second Memory limit: 64 MB Background The database of the Pentagon contains a top-secret information. We don’t know what the information is — you

ural 1014. Product of Digits贪心

1014. Product of Digits Time limit: 1.0 second Memory limit: 64 MB Your task is to find the minimal positive integer number  Q so that the product of digits of  Q is exactly equal to  N. Inpu

hdu 6198 dfs枚举找规律+矩阵乘法

number number number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description We define a sequence  F : ⋅   F0=0,F1=1 ; ⋅   Fn=Fn

深度优先(DFS)和广度优先(BFS)——算法

深度优先 深度优先搜索算法(英语:Depth-First-Search,DFS)是一种用于遍历或搜索树或图的算法。 沿着树的深度遍历树的节点,尽可能深的搜索树的分支,当节点v的所在边都己被探寻过,搜索将回溯到发现节点v的那条边的起始节点。这一过程一直进行到已发现从源节点可达的所有节点为止。如果还存在未被发现的节点,则选择其中一个作为源节点并重复以上过程,整个进程反复进行直到所有节点都被访

nyoj99(并查集+欧拉路+dfs)

单词拼接 时间限制: 3000 ms  |  内存限制: 65535 KB 难度: 5 描述 给你一些单词,请你判断能否把它们首尾串起来串成一串。 前一个单词的结尾应该与下一个单词的道字母相同。 如 aloha dog arachnid gopher tiger rat   可以拼接成:aloha.arachnid.dog.gopher.rat.tiger 输入 第一行是一个整