Skip to content

Instantly share code, notes, and snippets.

@zsrinivas
Created March 21, 2015 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zsrinivas/f999f7b93ecf4134a39a to your computer and use it in GitHub Desktop.
Save zsrinivas/f999f7b93ecf4134a39a to your computer and use it in GitHub Desktop.
TRIGALGE - Easy Calculation | http://www.spoj.com/problems/TRIGALGE/
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# pylint: disable=invalid-name,missing-docstring,bad-builtin
from sys import stdin
from math import sin
def trigagle(a, b, c):
xpos = 1000000
xneg = -1000000
prev = None
while prev != round((xpos + xneg) / 2.0, 6):
avg = (xpos + xneg) / 2.0
favg = a*avg + b*sin(avg) - c
if favg == 0:
return round(avg, 6)
elif favg > 0:
xpos = avg
else:
xneg = avg
prev = round(avg, 6)
return prev
def main():
dstream = map(int, stdin.read().split())
out = bytearray()
puts = out.extend
for t in xrange(dstream[0]):
puts(b'{:6f}\n'.format(
trigagle(dstream[3*t + 1], dstream[3*t + 2], dstream[3*t + 3])))
print out
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment