exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 236cf46d0208c1d016a17c21c46dc048 | train_001.jsonl | 1595342100 | You are given two arrays of integers $$$a_1,\ldots,a_n$$$ and $$$b_1,\ldots,b_m$$$.Your task is to find a non-empty array $$$c_1,\ldots,c_k$$$ that is a subsequence of $$$a_1,\ldots,a_n$$$, and also a subsequence of $$$b_1,\ldots,b_m$$$. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, find any. If there are no such arrays, you should report about it.A sequence $$$a$$$ is a subsequence of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero) elements. For example, $$$[3,1]$$$ is a subsequence of $$$[3,2,1]$$$ and $$$[4,3,1]$$$, but not a subsequence of $$$[1,3,3,7]$$$ and $$$[3,10,4]$$$. | 256 megabytes | import java.util.*;
public class b1 {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int m=sc.nextInt();
int arr[]=new int[n];
int brr[]=new int[m];
List<Integer> li=new ArrayList<Integer>();
List<Integer> li1=new ArrayList<Integer>();
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
li.add(arr[i]);
}
for(int j=0;j<m;j++)
{
brr[j]=sc.nextInt();
li1.add(brr[j]);
}
li.retainAll(li1);
if(li.size()!=0)
{
System.out.println("YES");
System.out.println("1"+" "+li.get(0));
}
else
{
System.out.println("NO");
}
}
}
}
| Java | ["5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5"] | 1 second | ["YES\n1 4\nYES\n1 3\nNO\nYES\n1 3\nYES\n1 2"] | NoteIn the first test case, $$$[4]$$$ is a subsequence of $$$[10, 8, 6, 4]$$$ and $$$[1, 2, 3, 4, 5]$$$. This array has length $$$1$$$, it is the smallest possible length of a subsequence of both $$$a$$$ and $$$b$$$.In the third test case, no non-empty subsequences of both $$$[3]$$$ and $$$[2]$$$ exist, so the answer is "NO". | Java 11 | standard input | [
"brute force"
] | 776a06c14c6fa3ef8664eec0b4d50824 | The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$) — the number of test cases. Next $$$3t$$$ lines contain descriptions of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n,m\le 1000$$$) — the lengths of the two arrays. The second line of each test case contains $$$n$$$ integers $$$a_1,\ldots,a_n$$$ ($$$1\le a_i\le 1000$$$) — the elements of the first array. The third line of each test case contains $$$m$$$ integers $$$b_1,\ldots,b_m$$$ ($$$1\le b_i\le 1000$$$) — the elements of the second array. It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ across all test cases does not exceed $$$1000$$$ ($$$\sum\limits_{i=1}^t n_i, \sum\limits_{i=1}^t m_i\le 1000$$$). | 800 | For each test case, output "YES" if a solution exists, or "NO" otherwise. If the answer is "YES", on the next line output an integer $$$k$$$ ($$$1\le k\le 1000$$$) — the length of the array, followed by $$$k$$$ integers $$$c_1,\ldots,c_k$$$ ($$$1\le c_i\le 1000$$$) — the elements of the array. If there are multiple solutions with the smallest possible $$$k$$$, output any. | standard output | |
PASSED | 664c08fd5de05e2b6c549bf7cc0a8d47 | train_001.jsonl | 1595342100 | You are given two arrays of integers $$$a_1,\ldots,a_n$$$ and $$$b_1,\ldots,b_m$$$.Your task is to find a non-empty array $$$c_1,\ldots,c_k$$$ that is a subsequence of $$$a_1,\ldots,a_n$$$, and also a subsequence of $$$b_1,\ldots,b_m$$$. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, find any. If there are no such arrays, you should report about it.A sequence $$$a$$$ is a subsequence of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero) elements. For example, $$$[3,1]$$$ is a subsequence of $$$[3,2,1]$$$ and $$$[4,3,1]$$$, but not a subsequence of $$$[1,3,3,7]$$$ and $$$[3,10,4]$$$. | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class common_subsequence_codeforces {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
while (t!=0){
t--;
int n = input.nextInt();
int m = input.nextInt();
ArrayList<Integer> a = new ArrayList<>();
ArrayList<Integer> b = new ArrayList<>();
for(int i=0;i<n;i++){
a.add(input.nextInt());
}
for(int j =0;j<m;j++){
b.add(input.nextInt());
//System.out.println("+1");
}
//int l = Math.max(n,m);
boolean b1 = true;
// for(int i=0;i<n;i++){
// System.out.print(a.get(i)+" ");
// }
// System.out.println();
// for(int j =0;j<m;j++){
// System.out.print(b.get(j)+" ");
// }
for(int i=0;i<n;i++){
for(int j =0;j<m;j++){
if(a.get(i).equals(b.get(j))){
System.out.println("YES ");
System.out.println("1 "+a.get(i));
b1=false;
break;
}
}
if(!b1){
break;
}
}
if(b1) System.out.println("NO");
}
}
}
| Java | ["5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5"] | 1 second | ["YES\n1 4\nYES\n1 3\nNO\nYES\n1 3\nYES\n1 2"] | NoteIn the first test case, $$$[4]$$$ is a subsequence of $$$[10, 8, 6, 4]$$$ and $$$[1, 2, 3, 4, 5]$$$. This array has length $$$1$$$, it is the smallest possible length of a subsequence of both $$$a$$$ and $$$b$$$.In the third test case, no non-empty subsequences of both $$$[3]$$$ and $$$[2]$$$ exist, so the answer is "NO". | Java 11 | standard input | [
"brute force"
] | 776a06c14c6fa3ef8664eec0b4d50824 | The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$) — the number of test cases. Next $$$3t$$$ lines contain descriptions of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n,m\le 1000$$$) — the lengths of the two arrays. The second line of each test case contains $$$n$$$ integers $$$a_1,\ldots,a_n$$$ ($$$1\le a_i\le 1000$$$) — the elements of the first array. The third line of each test case contains $$$m$$$ integers $$$b_1,\ldots,b_m$$$ ($$$1\le b_i\le 1000$$$) — the elements of the second array. It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ across all test cases does not exceed $$$1000$$$ ($$$\sum\limits_{i=1}^t n_i, \sum\limits_{i=1}^t m_i\le 1000$$$). | 800 | For each test case, output "YES" if a solution exists, or "NO" otherwise. If the answer is "YES", on the next line output an integer $$$k$$$ ($$$1\le k\le 1000$$$) — the length of the array, followed by $$$k$$$ integers $$$c_1,\ldots,c_k$$$ ($$$1\le c_i\le 1000$$$) — the elements of the array. If there are multiple solutions with the smallest possible $$$k$$$, output any. | standard output | |
PASSED | 816d1272bdf2095abdc14ee96f61f896 | train_001.jsonl | 1595342100 | You are given two arrays of integers $$$a_1,\ldots,a_n$$$ and $$$b_1,\ldots,b_m$$$.Your task is to find a non-empty array $$$c_1,\ldots,c_k$$$ that is a subsequence of $$$a_1,\ldots,a_n$$$, and also a subsequence of $$$b_1,\ldots,b_m$$$. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, find any. If there are no such arrays, you should report about it.A sequence $$$a$$$ is a subsequence of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero) elements. For example, $$$[3,1]$$$ is a subsequence of $$$[3,2,1]$$$ and $$$[4,3,1]$$$, but not a subsequence of $$$[1,3,3,7]$$$ and $$$[3,10,4]$$$. | 256 megabytes | /*
-------------------------------------------------------------------
* @Name: 1382A Common Subsequence
* @Author: Yanan
* @Create Time: 2020/7/23 22:35:46 (UTC+08:00)
* @Url: https://codeforces.com/contest/1382/problem/A
* @Description:
-------------------------------------------------------------------
*/
import java.io.*;
import java.util.*;
public class CF_1382A_CommonSubsequence
{
public static void main(String[] args) throws IOException
{
// if (System.getProperty("ONLINE_JUDGE") == null)
// {
// // redirect stdin/stdout to local file
// System.setIn(new FileInputStream(new File("CF_1382A_CommonSubsequence.in")));
// System.setOut(new PrintStream(new File("CF_1382A_CommonSubsequence.out")));
// }
Scanner in = new Scanner(System.in);
PrintStream out = System.out;
new CF_1382A_CommonSubsequence_Solution().Solve(in, out);
in.close();
out.close();
}
}
class CF_1382A_CommonSubsequence_Solution
{
public void Solve(Scanner in, PrintStream out)
{
/*
* int n = in.nextInt(); // read input as integer long k = in.nextLong(); //
* read input as long double d = in.nextDouble(); // read input as double String
* str = in.next(); // read input as String String s = in.nextLine(); // read
* whole line as String
*/
// out.println("OK");
int t = in.nextInt();
for (int i = 0; i < t; ++i)
{
int n = in.nextInt(), m = in.nextInt();
var f = new int[1200];
Arrays.fill(f, 0);
for (int j = 0; j < n; ++j)
{
int temp = in.nextInt();
f[temp] = 1;
}
boolean found = false;
for (int j = 0; j < m; ++j)
{
int temp = in.nextInt();
if (f[temp] == 1 && found == false)
{
found = true;
out.println("YES");
out.print("1 ");
out.println(temp);
}
}
if (found == false)
{
out.println("NO");
}
}
}
}
| Java | ["5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5"] | 1 second | ["YES\n1 4\nYES\n1 3\nNO\nYES\n1 3\nYES\n1 2"] | NoteIn the first test case, $$$[4]$$$ is a subsequence of $$$[10, 8, 6, 4]$$$ and $$$[1, 2, 3, 4, 5]$$$. This array has length $$$1$$$, it is the smallest possible length of a subsequence of both $$$a$$$ and $$$b$$$.In the third test case, no non-empty subsequences of both $$$[3]$$$ and $$$[2]$$$ exist, so the answer is "NO". | Java 11 | standard input | [
"brute force"
] | 776a06c14c6fa3ef8664eec0b4d50824 | The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$) — the number of test cases. Next $$$3t$$$ lines contain descriptions of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n,m\le 1000$$$) — the lengths of the two arrays. The second line of each test case contains $$$n$$$ integers $$$a_1,\ldots,a_n$$$ ($$$1\le a_i\le 1000$$$) — the elements of the first array. The third line of each test case contains $$$m$$$ integers $$$b_1,\ldots,b_m$$$ ($$$1\le b_i\le 1000$$$) — the elements of the second array. It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ across all test cases does not exceed $$$1000$$$ ($$$\sum\limits_{i=1}^t n_i, \sum\limits_{i=1}^t m_i\le 1000$$$). | 800 | For each test case, output "YES" if a solution exists, or "NO" otherwise. If the answer is "YES", on the next line output an integer $$$k$$$ ($$$1\le k\le 1000$$$) — the length of the array, followed by $$$k$$$ integers $$$c_1,\ldots,c_k$$$ ($$$1\le c_i\le 1000$$$) — the elements of the array. If there are multiple solutions with the smallest possible $$$k$$$, output any. | standard output | |
PASSED | 29f744f3241b0de5632acf0ae5615eb5 | train_001.jsonl | 1555425300 | There are $$$n$$$ students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.The $$$i$$$-th student has integer programming skill $$$a_i$$$. All programming skills are distinct and between $$$1$$$ and $$$n$$$, inclusive.Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and $$$k$$$ closest students to the left of him and $$$k$$$ closest students to the right of him (if there are less than $$$k$$$ students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. | 256 megabytes | import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class E {
public static void main(String[] args) throws IOException {
Scanner seer = new Scanner(System.in);
int n = seer.nextInt();
int k = seer.nextInt();
int[] arr = new int[n];
int[] rev = new int[n];
for(int i = 0; i < n; i++){
arr[i] = seer.nextInt()-1;
rev[arr[i]] = i;
}
int[] left = new int[n];
int[] right = new int[n];
for(int i = 0; i < n; i++){
if(i == 0) left[i] = -1;
else left[i] = i-1;
if(i == n-1) right[i] = -1;
else right[i] = i+1;
}
int[] val = new int[n];
int big = n-1;
int team = 1;
while(big >= 0){
if(val[rev[big]] != 0){
big--; continue;
}
int i = rev[big];
val[i] = team;
int l = left[i];
for(int j = 0; j < k; j++){
if(l >= 0){
val[l] = team;
l = left[l];
}
}
int r = right[i];
for(int j = 0; j < k; j++){
if(r >= 0){
val[r] = team;
r = right[r];
}
}
if(l >= 0) right[l] = r;
if(r >= 0) left[r] = l;
big--;
team = -team;
}
StringBuilder sb = new StringBuilder();
for(int i = 0; i < n; i++){
if(val[i] == 1) sb.append("1");
else sb.append("2");
}
System.out.println(sb.toString());
}
} | Java | ["5 2\n2 4 5 3 1", "5 1\n2 1 3 5 4", "7 1\n7 2 1 3 5 4 6", "5 1\n2 4 5 3 1"] | 2 seconds | ["11111", "22111", "1121122", "21112"] | NoteIn the first example the first coach chooses the student on a position $$$3$$$, and the row becomes empty (all students join the first team).In the second example the first coach chooses the student on position $$$4$$$, and the row becomes $$$[2, 1]$$$ (students with programming skills $$$[3, 4, 5]$$$ join the first team). Then the second coach chooses the student on position $$$1$$$, and the row becomes empty (and students with programming skills $$$[1, 2]$$$ join the second team).In the third example the first coach chooses the student on position $$$1$$$, and the row becomes $$$[1, 3, 5, 4, 6]$$$ (students with programming skills $$$[2, 7]$$$ join the first team). Then the second coach chooses the student on position $$$5$$$, and the row becomes $$$[1, 3, 5]$$$ (students with programming skills $$$[4, 6]$$$ join the second team). Then the first coach chooses the student on position $$$3$$$, and the row becomes $$$[1]$$$ (students with programming skills $$$[3, 5]$$$ join the first team). And then the second coach chooses the remaining student (and the student with programming skill $$$1$$$ joins the second team).In the fourth example the first coach chooses the student on position $$$3$$$, and the row becomes $$$[2, 1]$$$ (students with programming skills $$$[3, 4, 5]$$$ join the first team). Then the second coach chooses the student on position $$$1$$$, and the row becomes empty (and students with programming skills $$$[1, 2]$$$ join the second team). | Java 8 | standard input | [
"data structures",
"implementation",
"sortings"
] | 235131226fee9d04efef4673185c1c9b | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the programming skill of the $$$i$$$-th student. It is guaranteed that all programming skills are distinct. | 1,800 | Print a string of $$$n$$$ characters; $$$i$$$-th character should be 1 if $$$i$$$-th student joins the first team, or 2 otherwise. | standard output | |
PASSED | ec351ff38958a1fc018954fe603d1418 | train_001.jsonl | 1555425300 | There are $$$n$$$ students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.The $$$i$$$-th student has integer programming skill $$$a_i$$$. All programming skills are distinct and between $$$1$$$ and $$$n$$$, inclusive.Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and $$$k$$$ closest students to the left of him and $$$k$$$ closest students to the right of him (if there are less than $$$k$$$ students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. | 256 megabytes | import java.util.*;
public class Main{
class Node implements Comparable<Node>{
int ord,power;
Node nxt,prv;
public Node(int a , int b){
ord=a;
power=b;
}
public int compareTo(Node other) {
return -this.power+other.power;
}
}
Scanner in = new Scanner(System.in);
int n,k;
Queue<Node> q = new PriorityQueue<Node>();
public Main() {
n=in.nextInt();
k=in.nextInt();
Node head = new Node(-1,-1);
head.nxt=null;
head.prv=null;
Node pre=head;
for(int i=0;i<n;i++) {
Node now = new Node(i,in.nextInt());
q.add(now);
pre.nxt=now;
now.prv=pre;
now.nxt=null;
pre=now;
}
head.prv=pre;
pre.nxt=head;
int[] ans = new int[n];
Arrays.fill(ans, 0);
int team=1;
while(!q.isEmpty()) {
Node now = q.poll();
if (ans[now.ord]==0) {
for (int i=0;i<k;i++) {
if (now.prv!=head) {
//System.out.println(now.prv.power+"<");
ans[now.prv.ord]=team;
now.prv.prv.nxt=now;
now.prv=now.prv.prv;
}
if (now.nxt!=head) {
//System.out.println(">"+now.nxt.power);
ans[now.nxt.ord]=team;
now.nxt.nxt.prv=now;
now.nxt=now.nxt.nxt;
}
}
ans[now.ord]=team;
now.prv.nxt=now.nxt;
now.nxt.prv=now.prv;
team=team%2+1;
//System.out.println("------------------");
}
}
for (int i=0;i<ans.length;i++) {
System.out.print(ans[i]);
}
}
public static void main(String[] args) {
Main x = new Main();
}
} | Java | ["5 2\n2 4 5 3 1", "5 1\n2 1 3 5 4", "7 1\n7 2 1 3 5 4 6", "5 1\n2 4 5 3 1"] | 2 seconds | ["11111", "22111", "1121122", "21112"] | NoteIn the first example the first coach chooses the student on a position $$$3$$$, and the row becomes empty (all students join the first team).In the second example the first coach chooses the student on position $$$4$$$, and the row becomes $$$[2, 1]$$$ (students with programming skills $$$[3, 4, 5]$$$ join the first team). Then the second coach chooses the student on position $$$1$$$, and the row becomes empty (and students with programming skills $$$[1, 2]$$$ join the second team).In the third example the first coach chooses the student on position $$$1$$$, and the row becomes $$$[1, 3, 5, 4, 6]$$$ (students with programming skills $$$[2, 7]$$$ join the first team). Then the second coach chooses the student on position $$$5$$$, and the row becomes $$$[1, 3, 5]$$$ (students with programming skills $$$[4, 6]$$$ join the second team). Then the first coach chooses the student on position $$$3$$$, and the row becomes $$$[1]$$$ (students with programming skills $$$[3, 5]$$$ join the first team). And then the second coach chooses the remaining student (and the student with programming skill $$$1$$$ joins the second team).In the fourth example the first coach chooses the student on position $$$3$$$, and the row becomes $$$[2, 1]$$$ (students with programming skills $$$[3, 4, 5]$$$ join the first team). Then the second coach chooses the student on position $$$1$$$, and the row becomes empty (and students with programming skills $$$[1, 2]$$$ join the second team). | Java 8 | standard input | [
"data structures",
"implementation",
"sortings"
] | 235131226fee9d04efef4673185c1c9b | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the programming skill of the $$$i$$$-th student. It is guaranteed that all programming skills are distinct. | 1,800 | Print a string of $$$n$$$ characters; $$$i$$$-th character should be 1 if $$$i$$$-th student joins the first team, or 2 otherwise. | standard output | |
PASSED | 8e66b6f15bd6a491f23740dafbf4c726 | train_001.jsonl | 1555425300 | There are $$$n$$$ students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.The $$$i$$$-th student has integer programming skill $$$a_i$$$. All programming skills are distinct and between $$$1$$$ and $$$n$$$, inclusive.Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and $$$k$$$ closest students to the left of him and $$$k$$$ closest students to the right of him (if there are less than $$$k$$$ students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. | 256 megabytes | import java.io.*;
import java.util.*;
public class TwoTeams {
public static void main(String[] args) throws IOException {
Scanner scan=new Scanner(System.in);
PrintWriter pr=new PrintWriter(System.out);
int n=scan.nextInt();
int k=scan.nextInt();
int[] idx=new int[n+1];
int[] left=new int[n+1];
int[] right=new int[n+1];
int[] status=new int[n+1];
for(int i=1;i<=n;i++){
idx[scan.nextInt()]=i;
left[i]=i-1;
right[i]=i+1;
}
int max=n;
double s=-0.5;
while(max>0){
int idxMax=idx[max];
status[idxMax]=(int)(1.5+s);
int count=0;
int l=left[idxMax];
while(l>0 && count<k){
status[l]=(int)(1.5+s);
l=left[l];
count++;
}
count=0;
int r=right[idxMax];
while(r<n+1 && count<k){
status[r]=(int)(1.5+s);
r=right[r];
count++;
}
if(r<n+1)
left[r]=l;
if(l>0)
right[l]=r;
s=s*-1;
while(status[idx[max]]!=0 && max>0){
max--;
}
}
for(int i=1;i<=n;i++)
pr.print(status[i]);
pr.close();
}
}
| Java | ["5 2\n2 4 5 3 1", "5 1\n2 1 3 5 4", "7 1\n7 2 1 3 5 4 6", "5 1\n2 4 5 3 1"] | 2 seconds | ["11111", "22111", "1121122", "21112"] | NoteIn the first example the first coach chooses the student on a position $$$3$$$, and the row becomes empty (all students join the first team).In the second example the first coach chooses the student on position $$$4$$$, and the row becomes $$$[2, 1]$$$ (students with programming skills $$$[3, 4, 5]$$$ join the first team). Then the second coach chooses the student on position $$$1$$$, and the row becomes empty (and students with programming skills $$$[1, 2]$$$ join the second team).In the third example the first coach chooses the student on position $$$1$$$, and the row becomes $$$[1, 3, 5, 4, 6]$$$ (students with programming skills $$$[2, 7]$$$ join the first team). Then the second coach chooses the student on position $$$5$$$, and the row becomes $$$[1, 3, 5]$$$ (students with programming skills $$$[4, 6]$$$ join the second team). Then the first coach chooses the student on position $$$3$$$, and the row becomes $$$[1]$$$ (students with programming skills $$$[3, 5]$$$ join the first team). And then the second coach chooses the remaining student (and the student with programming skill $$$1$$$ joins the second team).In the fourth example the first coach chooses the student on position $$$3$$$, and the row becomes $$$[2, 1]$$$ (students with programming skills $$$[3, 4, 5]$$$ join the first team). Then the second coach chooses the student on position $$$1$$$, and the row becomes empty (and students with programming skills $$$[1, 2]$$$ join the second team). | Java 8 | standard input | [
"data structures",
"implementation",
"sortings"
] | 235131226fee9d04efef4673185c1c9b | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the programming skill of the $$$i$$$-th student. It is guaranteed that all programming skills are distinct. | 1,800 | Print a string of $$$n$$$ characters; $$$i$$$-th character should be 1 if $$$i$$$-th student joins the first team, or 2 otherwise. | standard output | |
PASSED | 35a8cec6b6fa0a672da2da5a68ada9af | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class B_59_Fortune_Telling {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
int n=input.nextInt();
int odd=0,even=0,sum=0;
int[] num=new int[n];
int i;
for(i=0;i<n;i++){
num[i]=input.nextInt();
if(num[i]%2==0)
even++;
else
odd++;
sum=sum+num[i];
}
//System.out.println(sum);
Arrays.sort(num);
if(odd==0)
System.out.println(0);
else if(odd%2==1)
System.out.println(sum);
else if(odd%2==0){
for(i=0;i<n;i++){
if(num[i]%2!=0){
sum=sum-num[i];
break;
}
}
System.out.println(sum);
}
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | cd863d2ffe13ccb6ce87675f72ba3165 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int [n];
int x=102;
int y=102;
int sum=0;
for (int i = 0; i < a.length; i++) {
a[i]=sc.nextInt();
sum+=a[i];
if(a[i] %2 ==1) x=Math.min(x, a[i]);
}
Arrays.sort(a);
int z=0;
for (int i = 0; i < a.length; i++) {
if(y<a[i] && a[i]%2==0) {z=a[i];break;}
}
if(sum%2==1) {System.out.println(sum); return;}
else{
if(x==102){System.out.println("0");return;}
System.out.println(sum-x);
}
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | b99a0f3df63426f181d564e715776de6 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// StringTokenizer st = new StringTokenizer(in.readLine());
// Scanner s = new Scanner(System.in);
int n = Integer.parseInt(in.readLine());
int[] mas = new int[n];
int sum = 0;
StringTokenizer st = new StringTokenizer(in.readLine());
for(int i = 0;i < n;i++) {
mas[i] = Integer.parseInt(st.nextToken());
sum += mas[i];
}
if(sum % 2 == 1) {
out.println(sum);
}else{
Arrays.sort(mas);
for(int i = 0;i < n;i++) {
if(mas[i] % 2 == 1) {
out.println(sum-mas[i]);
return;
}
}
out.println(0);
}
}
} | Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | d81a1a29b385daa084acffe77e6aeb0b | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
BufferedReader in;
StringTokenizer str = null;
PrintWriter out;
private String next() throws Exception{
while (str == null || !str.hasMoreElements())
str = new StringTokenizer(in.readLine());
return str.nextToken();
}
private int nextInt() throws Exception{
return Integer.parseInt(next());
}
public void run() throws Exception{
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
int n = nextInt();
int []a = new int[n];
int sum = 0, odd = Integer.MAX_VALUE;
for(int i=0;i<n;i++) {
a[i] = nextInt();
sum+=a[i];
if (a[i] % 2 == 1) {
odd = Math.min(odd, a[i]);
}
}
if (sum % 2 == 1){
out.println(sum);
}else{
if (odd == Integer.MAX_VALUE) out.println(0);
else{
out.println(sum - odd);
}
}
out.close();
}
public static void main(String args[]) throws Exception{
new Main().run();
}
} | Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | d2c695999664ead674991401aef91aae | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes |
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class P59B {
public P59B() {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> flowersEven = new ArrayList<>();
ArrayList<Integer> flowersOdd = new ArrayList<>();
for (int i = 0; i < n; i++){
int k = sc.nextInt();
if (k % 2 == 0){
flowersEven.add(k);
}
else {
flowersOdd.add(k);
}
}
sc.close();
Collections.sort(flowersEven);
Collections.sort(flowersOdd);
if (flowersOdd.size() == 0){
System.out.println(0);
return;
}
int sum = 0;
if (flowersOdd.size() % 2 == 1){
for (int i = 0; i < flowersOdd.size(); i++){
sum += flowersOdd.get(i);
}
}
else {
for (int i = 1; i < flowersOdd.size(); i++){
sum += flowersOdd.get(i);
}
}
for (int i = 0; i < flowersEven.size(); i++){
sum += flowersEven.get(i);
}
System.out.println(sum);
}
public static void main(String[] args) {
new P59B();
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 8af4209614e9dfd29f1633f309f79822 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.io.*;
import java.util.*;
public class j
{
public static void main(String a[])throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int t=0,j=0,p=0,m=105,n=0,k=0,i=0;
String s;
n=Integer.parseInt(b.readLine());
s=b.readLine();
StringTokenizer c=new StringTokenizer(s);
for(i=0;i<n;i++)
{
k=Integer.parseInt(c.nextToken());
if(k%2==0)
t+=k;
else
{
p+=k;
j++;
if(k<m)
m=k;
}
}
if(j==0)
{
System.out.print("0");
System.exit(0);
}
else
{
if(j%2==1)
System.out.print(p+t);
else
System.out.print(p+t-m);
}
}
} | Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 221b30468ce9f694631fe6dc87b439fb | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static boolean bg = true;
public static void main(String[] args) throws Exception {
ST in = new ST();
int n1 = in.ni();
int[] l1 = new int[n1];
for (int i = 0;i<n1;i++){
l1[i] = in.ni();
}
HashSet<Integer> s1 = new HashSet();
HashSet<Integer> s2 = new HashSet();
s1.add(0);
for (int i = 0;i<n1;i++){
int cur = l1[i];
for (int e: s1){
s2.add(e);
s2.add(e+cur);
}
s1 = s2;
s2 = new HashSet();
}
int max = 0;
for (int e: s1){
if (e%2==1) if (e> max) max = e;
}
pn(max);
}
private static BigInteger bi(long n1) {
return BigInteger.valueOf(n1);
}
private static void p(Object o1) {
System.out.print(o1);
}
private static void pn(Object o1) {
System.out.println(o1);
}
private static void px(Object... o1) {
System.out.println(Arrays.deepToString(o1));
}
private static void ex() {
System.exit(0);
}
private static class LR {
BufferedReader k1 = null;
public LR() throws Exception {
k1 = new BufferedReader(new InputStreamReader(System.in));
}
public String nx() throws Exception {
return k1.readLine();
}
}
private static class ST {
StreamTokenizer k1 = null;
public ST() throws Exception {
k1 = new StreamTokenizer(System.in);
}
public int ni() throws Exception {
k1.nextToken();
return (int) k1.nval;
}
public double nd() throws Exception {
k1.nextToken();
return (double) k1.nval;
}
public long nl() throws Exception {
k1.nextToken();
return (long) k1.nval;
}
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 1ab25d71e33404b3c837842dbdb8b605 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
public class Task059B {
public static void main(String... args) throws NumberFormatException,
IOException {
Solution.main(System.in, System.out);
}
static class Scanner {
private final BufferedReader br;
private String[] cache;
private int cacheIndex;
Scanner(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
cache = new String[0];
cacheIndex = 0;
}
int nextInt() throws IOException {
if (cacheIndex >= cache.length) {
cache = br.readLine().split(" ");
cacheIndex = 0;
}
return Integer.parseInt(cache[cacheIndex++]);
}
int nextInt(int radix) throws IOException {
if (cacheIndex >= cache.length) {
cache = br.readLine().split(" ");
cacheIndex = 0;
}
return Integer.parseInt(cache[cacheIndex++], radix);
}
long nextLong() throws IOException {
if (cacheIndex >= cache.length) {
cache = br.readLine().split(" ");
cacheIndex = 0;
}
return Long.parseLong(cache[cacheIndex++]);
}
double nextDouble() throws IOException {
if (cacheIndex >= cache.length) {
cache = br.readLine().split(" ");
cacheIndex = 0;
}
return Double.parseDouble(cache[cacheIndex++]);
}
String next() throws IOException {
if (cacheIndex >= cache.length) {
cache = br.readLine().split(" ");
cacheIndex = 0;
}
return cache[cacheIndex++];
}
void close() throws IOException {
br.close();
}
}
static class Solution {
public static void main(InputStream is, OutputStream os)
throws NumberFormatException, IOException {
PrintWriter pw = new PrintWriter(os);
Scanner sc = new Scanner(is);
int n = sc.nextInt();
ArrayList<Integer> parzyste = new ArrayList<>(n);
ArrayList<Integer> nieparzyste = new ArrayList<>(n);
for(int i = 0 ; i < n ; i++){
int tmp = sc.nextInt();
if(tmp % 2 == 0){
parzyste.add(tmp);
} else {
nieparzyste.add(tmp);
}
}
Collections.sort(parzyste);
Collections.sort(nieparzyste);
if(nieparzyste.isEmpty()){
pw.println(0);
pw.flush();
sc.close();
return;
}
int retVal1 = 0;
for (Integer aParzyste : parzyste) {
retVal1 += aParzyste;
}
for(int i = 1 - (nieparzyste.size() % 2) ; i < nieparzyste.size() ; i++){
retVal1 += nieparzyste.get(i);
}
pw.println(retVal1);
pw.flush();
sc.close();
}
}
} | Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | b23a826157232de2868b6283e7e71e73 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
do {
int times = scan.nextInt(), aux;
int[] f = new int[times];
long suma = 0, k = 0;
for (int i = 0; i < times; i++)
suma += f[i] = scan.nextInt();
if (suma % 2 == 1)
System.out.println(suma);
else {
Arrays.sort(f);
long a = suma;
f:for (int i = 0; i < f.length; i++)
if (f[i] % 2 == 1) {
suma -= f[i];
break f;
}
System.out.println((suma==a)?0:suma);
}
} while (scan.hasNext());
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 96b48d97075b6467ceecb7626e1dfe21 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int n = s.nextInt(),min = 101,sum=0,v;
for (int i = 1;i <= n;i++)
{
v = s.nextInt();
sum += v;
if (v % 2 == 1 && v < min)
min = v;
}
if (sum % 2 == 1)
System.out.println(sum);
else
if (min == 101)
System.out.println(0);
else
System.out.println(sum - min);
}
} | Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 7b0202fe9fb7fac2bcca60a4f458e5d2 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.io.IOException;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.util.HashMap;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.TreeSet;
import java.io.BufferedInputStream;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Zyflair Griffane
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
JoltyScanner in = new JoltyScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
}
class Task {
public void solve(int testNumber, JoltyScanner in, PrintWriter out) {
int n = in.nextInt();
int[] arr = InputUtil.readIntArray(in, n);
Arrays.sort(arr);
int min = 0;
int odd = 0;
for (int i = 0; i < n; i++) {
if (arr[i] % 2 == 1) {
odd++;
if (min == 0) {
min = arr[i];
}
}
}
out.println(min == 0 ? 0 : (IntArrayUtil.sum(arr) - (odd % 2 == 1 ? 0 : min)));
}
}
class JoltyScanner {
public static final int BUFFER_SIZE = 1 << 16;
public static final char NULL_CHAR = (char) -1;
byte[] buffer = new byte[BUFFER_SIZE];
boolean EOF_FLAG = false;
int bufferIdx = 0, size = 0;
char c = NULL_CHAR;
BufferedInputStream in;
public JoltyScanner(InputStream in) {
this.in = new BufferedInputStream(in, BUFFER_SIZE);
}
public int nextInt() {
long x = nextLong();
if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE) {
throw new ArithmeticException("Scanned value overflows integer");
}
return (int) x;
}
public long nextLong() {
boolean negative = false;
if (c == NULL_CHAR) {
c = nextChar();
}
for (; !EOF_FLAG && (c < '0' || c > '9'); c = nextChar()) {
if (c == '-') {
negative = true;
}
}
checkEOF();
long res = 0;
for (; c >= '0' && c <= '9'; c = nextChar()) {
res = (res << 3) + (res << 1) + c - '0';
}
return negative ? -res : res;
}
public char nextChar() {
if (EOF_FLAG) {
return NULL_CHAR;
}
while (bufferIdx == size) {
try {
size = in.read(buffer);
if (size == -1) {
throw new Exception();
}
} catch (Exception e) {
EOF_FLAG = true;
return NULL_CHAR;
}
if (size == -1) {
size = BUFFER_SIZE;
}
bufferIdx = 0;
}
return (char) buffer[bufferIdx++];
}
public void checkEOF() {
if (EOF_FLAG) {
throw new EndOfFileException();
}
}
public class EndOfFileException extends RuntimeException {
}
}
class InputUtil {
public static int[] readIntArray(JoltyScanner in, int size) {
int[] arr = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = in.nextInt();
}
return arr;
}
}
class IntArrayUtil {
public static long sum(int[] arr) {
long res = 0;
for (int i: arr) {
res += i;
}
return res;
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | b8ea898e3fdafe9438ed4cb86108c881 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.*;
public class Amor {
/**
* @param args
*/
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int casos=in.nextInt();
int[] nros=new int[casos];
int total=0;
for(int i=0;i<casos;i++){
nros[i]=in.nextInt();
total+=nros[i];
}
Arrays.sort(nros);
for(int i=0;i < casos;i++){
if(total%2!=0){
break;
}else{
if(nros[i]%2!=0){
total-=nros[i];
}
}
}
if(total%2!=0){
System.out.println(total);
}else{
System.out.println(0);
}
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 2a5b0b5ab7835cccb2965d139c049083 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main (String...args){
Scanner input = new Scanner (System.in);
String y;
int x = Integer.parseInt(input.nextLine());
int n=0,menor=0,j=0;
y = input.nextLine();
String [] token = y.split ("\\s+");
for(int i=0; i<x; i++){
n+=Integer.parseInt(token[i]);
if(Integer.parseInt(token[i])%2!=0){
if(j==0){
menor=Integer.parseInt(token[i]);
j++;
}
if(menor> Integer.parseInt(token[i])){
menor = Integer.parseInt(token[i]);
}
}
}
if(n%2!=0){
System.out.println(n);
}else{
n=n-menor;
if(n%2!=0){
System.out.println(n);
}else{
System.out.println("0");
}
}
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | c2dc80a7e711ce7fdf56ea26d8d1008c | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes |
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author KHALED
*/
public class FortuneTelling {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int min=999999999;
int sum=0;
for (int i = 0; i < n; i++)
{
int k=scan.nextInt();
sum+=k;
if(k<min&&k%2==1)
min=k;
}
if(min!=999999999)
{
if(sum%2==0)
System.out.println(sum-min);
else
System.out.println(sum);
}
else
System.out.println(0);
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 70f8c0b58572d453190c1c6989518af5 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.Scanner;
public class B_55 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int [] a = new int [n+1];
int sum = 0;
int min = Integer.MAX_VALUE;
for (int i = 1; i <=n; i++) {
a[i]=sc.nextInt();
sum+=a[i];
if(a[i]%2==1){
if(a[i]<min) min = a[i];
}
}
if(sum%2==1){
System.out.println(sum);
return;
}
if(min==Integer.MAX_VALUE){
System.out.println(0);
}
else System.out.println(sum-min);
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 2fa87c14a42a714bf92be242db68c95a | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.*;
public class SinIsh2 {
public static void main(String [] args){
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int array[]=new int [n];
int a1=0;
int a2=0;
int min=Integer.MAX_VALUE;
for(int i=0;i<n;i++){
int a=in.nextInt();
array[i]=a;
if(a%2==0)
a1++;
else if(a%2==1){
min=Math.min(a,min);
a2++;
}
}
Arrays.sort(array);
if(a2==0)
System.out.print("0");
else if(a2%2==1){
a1=0;
for(int i=0;i<n;i++){
a1+=array[i];
}
System.out.print(a1);
}
else if(a2%2==0){
a1=0;
for(int i=n-1;i>=0;i--){
a1+=array[i];
}
a1=a1-min;
System.out.print(a1);
}
}
} | Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | d9bbcb0dd638bd4db89a9c6d13bc2a1e | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.Scanner;
public class P6 {
private static final Scanner IN = new Scanner(System.in);
public static void main(String[] args) {
long sum = 0;
long mi = Long.MAX_VALUE;
for (int i = IN.nextInt(); i > 0; i--) {
int n = IN.nextInt();
sum+=n;
if(n%2!=0)
mi = Math.min(mi, n);
}
if(sum%2==0){
if(mi==Long.MAX_VALUE) System.out.println(0);
else System.out.println(sum-mi);
}else System.out.println(sum);
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 16c501b50f795ad0b5999e3f2e553e20 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out, true);
Scanner in = new Scanner(System.in);
Main solver = new Main(in, out);
solver.run();
in.close();
out.close();
return;
}
Scanner in;
PrintWriter out;
public Main(Scanner i, PrintWriter o) {
in = i;
out = o;
}
Integer[] a = new Integer[100];
public void run() {
int n = in.nextInt();
int i, t;
int m = 0;
int s = 0;
for (i = 0; i < n; i++) {
t = in.nextInt();
if (t%2 == 0) {
s += t;
}
else {
a[m++] = t;
}
}
if (m == 0) {
out.print(0);
return;
}
Arrays.sort(a, 0, m, new RevComp());
int len = (m%2 == 0 ? m-1 : m);
for (i = 0; i < len; i++) {
s += a[i];
}
out.print(s);
return;
}
class RevComp implements Comparator<Integer> {
public int compare(Integer a, Integer b) {
return -Integer.compare(a, b);
}
}
} | Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | c8502dd4fe7ab13176f9e11eabd98a11 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
public class FortuneTelling {
public static void main(String ad[])throws Exception
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int a[]=new int[n];
int sum=0;
for(int i=0;i<n;i++)
sum+=a[i]=in.nextInt();
Arrays.sort(a);
if(sum%2!=0)
System.out.println(sum);
else
{
int k=0;
while(k<n&&(sum-a[k])%2==0)
{
k++;
}
if(k<n)
System.out.println(sum-a[k]);
else
System.out.println(0);
}
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 0f16f70c2b0beece1a6dc568b18b013d | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
/**
*
* @author Prateep
*/
public class JavaApplication1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB{
public void solve(int testNumber, InputReader in, PrintWriter out){
int n=in.nextInt();
int[] base=new int[n];
int minPetal=Integer.MAX_VALUE,sum=0;
for(int i=0;i<n;i++){
base[i]=in.nextInt();
sum+=base[i];
if(base[i]%2!=0)
minPetal=base[i]<minPetal?base[i]:minPetal;
}
if(minPetal==Integer.MAX_VALUE)
out.println("0");
else if(sum%2==0)
out.println(sum-minPetal);
else
out.println(sum);
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | e01871466482893a963ed5b802aa7793 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Fortune_Telling {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
br.readLine();
String[] x = br.readLine().split(" ");
int[] y = new int[x.length];
for (int c = 0; c < x.length; c++) {
y[c] = Integer.parseInt(x[c]);
}
int res = 0;
int counte = 0;
int counto = 0;
boolean even_odd = true;
for (int i = 0; i < y.length; i++) {
res = res + y[i];
if (y[i] % 2 != 0)
counto++;
}
if (counto == 0) {
System.out.println(0);
return;
}
if (counto % 2 == 0) {
int min = 999;
for (int c = 0; c < y.length; c++) {
if (y[c] % 2 != 0 && y[c] < min)
min = y[c];
}
res = res - min;
//System.out.println(min);
}
System.out.println(res);
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 235495a0f4d0c1d9a6e8615594dde0a2 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes |
import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner nm = new Scanner(System.in);
int n = nm.nextInt();
int a [] = new int[n+1];
int min_t=Integer.MAX_VALUE, min_j=Integer.MAX_VALUE,inc=0;
for (int i = 1; i <=n; i++) {
int k=nm.nextInt();
if (min_t>k && k%2==1) {
min_t=k;
}
if (min_j>k && k%2==0) {
min_j=k;
}
inc+=k;
}
if (inc%2==0) {
if ( (inc-min_t)%2==1) {
System.out.println(inc-min_t);
return;
}else{
System.out.println(0);
}
}else{
System.out.println(inc);
}
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | d2ce8ed27ce52f2ca0108c2c35254742 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.nio.charset.StandardCharsets;
import java.io.UnsupportedEncodingException;
public class Main
{
public static void main(String[] args)
{
InputReader in = new InputReader();
PrintWriter out = new PrintWriter(System.out);
int n=in.nextInt();
int []a=new int[n];
int num=0, sum=0, minn=105;
for(int i=0;i<n;i++)
{
a[i]=in.nextInt();
if(a[i]%2==1)
{
num++;
minn=Math.min(minn, a[i]);
}
sum+=a[i];
}
if(num%2==1)
out.println(sum);
else if(num==0)
out.println("0");
else
out.println(sum-minn);
out.close();
System.exit(0);
}
}
class InputReader
{
BufferedReader buf;
StringTokenizer tok;
InputReader()
{
buf = new BufferedReader(new InputStreamReader(System.in));
}
boolean hasNext()
{
while(tok == null || !tok.hasMoreElements())
{
try
{
tok = new StringTokenizer(buf.readLine());
}
catch(Exception e)
{
return false;
}
}
return true;
}
String next()
{
if(hasNext())
return tok.nextToken();
return null;
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
BigInteger nextBigInteger()
{
return new BigInteger(next());
}
BigDecimal nextBigDecimal()
{
return new BigDecimal(next());
}
} | Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | ff2922edd024a1db6f0cd47a9ea2c01b | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main
{
public static void main(String asdf[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String inpar[]=(br.readLine()).split(" ");
int ar[]=new int[n];
int noe=0,noo=0;
for(int i=0;i<n;i++)
{
ar[i]=Integer.parseInt(inpar[i]);
if(ar[i]%2==0)
noe++;
else
noo++;
}
Arrays.sort(ar);
if(noo==0)
{
System.out.println("0");
return ;
}
if(noe==0)
{
int til;
if(n%2==0)
til=1;
else
til=0;
int ans=0;
for(int i=n-1;i>=til;i--)
{
ans+=ar[i];
}
System.out.println(ans);
return;
}
int sum=0;
int noota;
if(noo%2==0)
noota=noo-1;
else
noota=noo;
int oddadded=0;
for(int i=n-1;i>=0;i--)
{
if(ar[i]%2==0)
sum+=ar[i];
else
{
if(oddadded<noota)
{
oddadded++;
sum+=ar[i];
}
}
}
System.out.println(sum);
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 269e8f2b9da9b86d3d69d37f502f746c | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main (String...args){
Scanner input = new Scanner (System.in);
String y;
int x = Integer.parseInt(input.nextLine());
int n=0,menor=0,j=0;
y = input.nextLine();
String [] token = y.split ("\\s+");
for(int i=0; i<x; i++){
n+=Integer.parseInt(token[i]);
if(Integer.parseInt(token[i])%2!=0){
if(j==0){
menor=Integer.parseInt(token[i]);
j++;
}
if(menor> Integer.parseInt(token[i])){
menor = Integer.parseInt(token[i]);
}
}
}
if(n%2!=0){
System.out.println(n);
}else{
n=n-menor;
if(n%2!=0){
System.out.println(n);
}else{
System.out.println("0");
}
}
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 9b91b0d050af8bbc4e662b615af1e05a | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.Scanner;
public class Adivinacion {
public static void main (String...args){
Scanner input = new Scanner (System.in);
String y;
int x = Integer.parseInt(input.nextLine());
int n=0,menor=0,j=0;
y = input.nextLine();
String [] token = y.split ("\\s+");
for(int i=0; i<x; i++){
n+=Integer.parseInt(token[i]);
if(Integer.parseInt(token[i])%2!=0){
if(j==0){
menor=Integer.parseInt(token[i]);
j++;
}
if(menor> Integer.parseInt(token[i])){
menor = Integer.parseInt(token[i]);
}
}
}
if(n%2!=0){
System.out.println(n);
}else{
n=n-menor;
if(n%2!=0){
System.out.println(n);
}else{
System.out.println("0");
}
}
}
}
| Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 46a0011db778cac0543626b665b60540 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main (String...args){
Scanner input = new Scanner (System.in);
String y;
int x = Integer.parseInt(input.nextLine());
int n=0,menor=0,j=0;
y = input.nextLine();
String [] token = y.split ("\\s+");
for(int i=0; i<x; i++){
n+=Integer.parseInt(token[i]);
if(Integer.parseInt(token[i])%2!=0){
if(j==0){
menor=Integer.parseInt(token[i]);
j++;
}
if(menor> Integer.parseInt(token[i])){
menor = Integer.parseInt(token[i]);
}
}
}
if(n%2!=0){
System.out.println(n);
}else{
n=n-menor;
if(n%2!=0){
System.out.println(n);
}else{
System.out.println("0");
}
}
}
} | Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 41121bdabdf864c3dbfc97223d0001b7 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Flor {
public static void main(String[] args) {
// http://codeforces.com/problemset/problem/59/B
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int ans = 0;
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt(); //ingreso y asuvez voy acumulando
ans += a[i];
}
Arrays.sort(a);
int i = 0;
while (ans % 2 == 0 && i < n) { //lo recorro siel resto es 1 quito ese elemento
if (a[i] % 2 == 1) {
ans -= a[i];
}
i++;
}
System.out.println((ans % 2 == 1) ? ans : "0");//si al final queda 1 lo muestro
}
} | Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | ac5e37a32d8fcd183ddfcf493c2e9552 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.io.*;
import java.util.*;
public class FortuneTelling {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(f.readLine());
StringTokenizer st = new StringTokenizer(f.readLine());
int[] a = new int[n];
int sum = 0;
int minodd = Integer.MAX_VALUE;
for (int i = 0; i < n; i++)
{
a[i] = Integer.parseInt(st.nextToken());
sum += a[i];
if (a[i] % 2 == 1 && a[i] < minodd)
minodd = a[i];
}
if (minodd == Integer.MAX_VALUE)
System.out.println(0);
else
{
if (sum % 2 == 0)
sum -= minodd;
System.out.println(sum);
}
}
} | Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | e66e0a818415a9eabf3e633c55c7b0d2 | train_001.jsonl | 1297440000 | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. | 256 megabytes | import java.util.Scanner;
public class flowers {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] c = new int[110];
int i;
int contimp = 0;
int contpar = 0;
int tot= 0;
int minimp = 999999999;
for( i= 0; i < n; i++){
c[i] = sc.nextInt();
if(c[i]%2 == 0){contpar++;}
else{
contimp++;
if(minimp > c[i]){ minimp = c[i];}
}
tot = tot + c[i];
}
if(contimp == 0){
System.out.println(0);
}
else if(contimp % 2 != 0){
System.out.println(tot);
}
else{ System.out.println(tot-minimp);}
}
} | Java | ["1\n1", "1\n2", "3\n5 6 7"] | 2 seconds | ["1", "0", "13"] | null | Java 7 | standard input | [
"implementation",
"number theory"
] | a5d56056fd66713128616bc7c2de8b22 | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | 1,200 | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | standard output | |
PASSED | 497c1817e645c6bcab52c5979e5a7f49 | train_001.jsonl | 1284130800 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | 256 megabytes | import java.util.Scanner;
public class C358 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] array = new int[n];
int[] minPref = new int[n];
int[] maxPref = new int[n];
int[] minSuf = new int[n];
int[] maxSuf = new int[n];
for (int i = 0; i < n; i++) {
array[i] = in.nextInt();
if (i == 0 || array[minPref[i - 1]] > array[i]) {
minPref[i] = i;
} else {
minPref[i] = minPref[i - 1];
}
if (i == 0 || array[maxPref[i - 1]] < array[i]) {
maxPref[i] = i;
} else {
maxPref[i] = maxPref[i - 1];
}
}
for (int i = n - 1; i >= 0; i--) {
if (i == n - 1 || array[minSuf[i + 1]] > array[i]) {
minSuf[i] = i;
} else {
minSuf[i] = minSuf[i + 1];
}
if (i == n - 1 || array[maxSuf[i + 1]] < array[i]) {
maxSuf[i] = i;
} else {
maxSuf[i] = maxSuf[i + 1];
}
}
for (int i = 1; i < n - 1; i++) {
if (array[minPref[i]] < array[i] && array[minSuf[i]] < array[i]) {
System.out.println(3);
System.out.println(minPref[i] + 1 + " " + (i + 1) + " " + (minSuf[i] + 1));
return;
}
if (array[maxPref[i]] > array[i] && array[maxSuf[i]] > array[i]) {
System.out.println(3);
System.out.println(maxPref[i] + 1 + " " + (i + 1) + " " + (maxSuf[i] + 1));
return;
}
}
System.out.println(0);
}
}
| Java | ["5\n67 499 600 42 23", "3\n1 2 3", "3\n2 3 1"] | 2 seconds | ["3\n1 3 5", "0", "3\n1 2 3"] | null | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 652c7852f1d0bab64ffd2219af4f59da | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | 1,900 | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | standard output | |
PASSED | 992ce0bf837d7a5a9663b02bb7b16144 | train_001.jsonl | 1284130800 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] arg) {
FastScanner scan = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = scan.nextInt();
int[] in = new int[n+1];
for(int i = 0; i < n; i++){
in[i] = scan.nextInt();
}
if(n == 1 || n == 2){
out.println(0);
} else {
int idx = -1;
boolean find = false;
for(int i = 0; i < n - 1; i++){
long a = (long)in[i+1] - (long)in[i];
if(a == 0) continue;
else {
if(idx == -1){
idx = i;
continue;
} else {
long before = (long) in[idx+1] - in[idx];
if(before * a < 0){
find = true;
out.println(3);
out.println((idx+1) + " " + (idx+2) + " " + (i+2));
break;
} else {
idx = i;
}
}
}
}
if(!find) out.println(0);
}
out.close();
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(InputStream is) {
try {
br = new BufferedReader(new InputStreamReader(is));
} catch (Exception e) {
e.printStackTrace();
}
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
return null;
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.valueOf(next());
}
}
}
| Java | ["5\n67 499 600 42 23", "3\n1 2 3", "3\n2 3 1"] | 2 seconds | ["3\n1 3 5", "0", "3\n1 2 3"] | null | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 652c7852f1d0bab64ffd2219af4f59da | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | 1,900 | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | standard output | |
PASSED | 1b76105d0312a87c5d28612a7a7c0df4 | train_001.jsonl | 1284130800 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | 256 megabytes | import java.util.*;
import java.io.*;
public class C27 {
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public InputReader() throws FileNotFoundException {
reader = new BufferedReader(new FileReader("d:/input.txt"));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
public class node{
int id , key;
public node(int id ,int key){
this.id = id;
this.key = key;
}
@Override
public String toString() {
return Integer.toString(id);
}
}
public boolean solve(ArrayList<node> list){
int cur = 0;
for(int i = 1 ; i < list.size() - 1 ; i ++){
if(list.get(i).key > list.get(i-1).key && list.get(i).key > list.get(i+1).key){
cur = i;
break;
}
}
if(cur != 0){
System.out.println(3);
System.out.println(list.get(cur-1)+" "+list.get(cur)+" "+list.get(cur+1));
return true;
}
return false;
}
public void run(){
InputReader reader = new InputReader(System.in);
int n = reader.nextInt();
int a[] = new int[n+1];
for(int i= 1 ; i <= n ; i ++)
a[i] = reader.nextInt();
ArrayList<node> list = new ArrayList<node>();
int pre = 0;
for(int i = 1 ; i <= n ; i++){
if(a[i] == a[pre]) continue;
else{
list.add(new node(i,a[i]));
pre = i;
}
}
if(!solve(list)){
for(int i = 1 ; i <= n ; i ++){
a[i] *= -1;
}
ArrayList<node> list2 = new ArrayList<node>();
for(int i = 0 ;i < list.size() ; i ++){
node tmp = list.get(i);
list2.add(new node(tmp.id,tmp.key*-1));
}
if(!solve(list2)){
System.out.println(0);
}
}
}
public static void main(String[] args) {
new C27().run();
}
}
| Java | ["5\n67 499 600 42 23", "3\n1 2 3", "3\n2 3 1"] | 2 seconds | ["3\n1 3 5", "0", "3\n1 2 3"] | null | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 652c7852f1d0bab64ffd2219af4f59da | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | 1,900 | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | standard output | |
PASSED | 727dc33a62c03dd559267d59b15bea84 | train_001.jsonl | 1284130800 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class cf27c {
public static void main(String[] args) {
FastIO in = new FastIO(), out = in;
int n = in.nextInt();
int[] v = new int[n];
for(int i=0; i<n; i++) v[i] = in.nextInt();
Cluster left = new Cluster(), right = new Cluster();
for(int i=0; i<n; i++) right.add(v[i]);
for(int i=0; i<n; i++) {
right.remove(v[i]);
// try something lower
Integer leftVal = left.lower(v[i]);
Integer rightVal = right.lower(v[i]);
if(leftVal != null && rightVal != null) {
out.println(3);
for(int j=0; j<i; j++)
if(v[j] == leftVal) {
out.print((j+1)+" ");
break;
}
out.print((i+1)+" ");
for(int j=i+1; j<n; j++)
if(v[j] == rightVal) {
out.print((j+1));
break;
}
out.close();
return;
}
// something higher
leftVal = left.higher(v[i]);
rightVal = right.higher(v[i]);
if(leftVal != null && rightVal != null) {
out.println(3);
for(int j=0; j<i; j++)
if(v[j] == leftVal) {
out.print((j+1)+" ");
break;
}
out.print((i+1)+" ");
for(int j=i+1; j<n; j++)
if(v[j] == rightVal) {
out.print((j+1));
break;
}
out.close();
return;
}
left.add(v[i]);
}
out.println(0);
out.close();
}
static class Cluster {
TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>();
Cluster() {}
void add(int x) {
if(!map.containsKey(x)) map.put(x,0);
map.put(x,map.get(x)+1);
}
void remove(int x) {
map.put(x, map.get(x)-1);
if(map.get(x) == 0) map.remove(x);
}
Integer higher(int x) {
return map.higherKey(x);
}
Integer lower(int x) {
return map.lowerKey(x);
}
}
static class FastIO extends PrintWriter {
BufferedReader br;
StringTokenizer st;
public FastIO() {
this(System.in,System.out);
}
public FastIO(InputStream in, OutputStream out) {
super(new BufferedWriter(new OutputStreamWriter(out)));
br = new BufferedReader(new InputStreamReader(in));
scanLine();
}
public void scanLine() {
try {
st = new StringTokenizer(br.readLine().trim());
} catch(Exception e) {
throw new RuntimeException(e.getMessage());
}
}
public int numTokens() {
if(!st.hasMoreTokens()) {
scanLine();
return numTokens();
}
return st.countTokens();
}
public String next() {
if(!st.hasMoreTokens()) {
scanLine();
return next();
}
return st.nextToken();
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["5\n67 499 600 42 23", "3\n1 2 3", "3\n2 3 1"] | 2 seconds | ["3\n1 3 5", "0", "3\n1 2 3"] | null | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 652c7852f1d0bab64ffd2219af4f59da | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | 1,900 | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | standard output | |
PASSED | 3d5c2a793b3bdc81943256b80f14d507 | train_001.jsonl | 1284130800 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class c27 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] arr = new int[n];
int minIdx=0, maxIdx=0;
arr[0] = in.nextInt();
for (int i = 1; i < arr.length; i++) {
arr[i] = in.nextInt();
if ((arr[i] > arr[minIdx] && arr[i] < arr[maxIdx]) ||
(maxIdx > minIdx && arr[i] < arr[maxIdx]) ||
(maxIdx < minIdx && arr[i] > arr[minIdx])) {
int[] out = {i, minIdx, maxIdx};
Arrays.sort(out);
System.out.println(3);
System.out.printf("%d %d %d\n", out[0]+1, out[1]+1, out[2]+1);
return;
}
if (arr[i] < arr[minIdx])
minIdx = i;
if (arr[i] > arr[maxIdx])
maxIdx = i;
}
System.out.println(0);
}
}
| Java | ["5\n67 499 600 42 23", "3\n1 2 3", "3\n2 3 1"] | 2 seconds | ["3\n1 3 5", "0", "3\n1 2 3"] | null | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 652c7852f1d0bab64ffd2219af4f59da | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | 1,900 | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | standard output | |
PASSED | 2937b9988873000548f2e8bed683efdd | train_001.jsonl | 1284130800 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | 256 megabytes | import java.io.*;
import java.util.*;
/**
* Created by peacefrog on 12/4/15.
* Time : 9:57 PM
*/
public class CF27C {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
PrintWriter out;
long timeBegin, timeEnd;
public void runIO() throws IOException {
timeBegin = System.currentTimeMillis();
InputStream inputStream;
OutputStream outputStream;
if (ONLINE_JUDGE) {
inputStream = System.in;
Reader.init(inputStream);
outputStream = System.out;
out = new PrintWriter(outputStream);
} else {
inputStream = new FileInputStream("/home/peacefrog/Dropbox/IdeaProjects/Problem Solving/input");
Reader.init(inputStream);
out = new PrintWriter(System.out);
}
solve();
out.flush();
out.close();
timeEnd = System.currentTimeMillis();
System.err.println("Time = " + (timeEnd - timeBegin));
}
/*
* Start Solution Here
*/
class Node implements Comparable<Node>{
int id , val;
public Node(int id, int val) {
this.id = id;
this.val = val;
}
@Override
public int compareTo(Node o) {
return Integer.compare(val , o.val);
}
}
private void solve() throws IOException {
int n = Reader.nextInt(); //This Variable default in Code Template
int arr[] = Reader.nextIntArray(n);
ArrayList<Node> s = new ArrayList<>();
int last = 0;
s.add(new Node(1 , arr[0]));
for (int i = 1; i < n; i++) {
if(arr[i] == arr[last]) continue;
s.add(new Node(i+1 , arr[i]));
last = i;
}
boolean found = false ;
Node[] t = new Node[s.size()];
t =s.toArray(t);
if(n > 2) {
for (int i = 1; i < t.length - 1; i++) {
if ((t[i + 1].val < t[i].val) && (t[i].val > t[i - 1].val)) {
out.println(3);
out.println(t[i - 1].id + " " + t[i].id + " " + t[i + 1].id);
found = true;
break;
}
}
if (!found) {
for (int i = 1; i < t.length - 1; i++) {
if ((t[i + 1].val > t[i].val) && (t[i].val < t[i - 1].val)) {
out.println(3);
out.println(t[i - 1].id + " " + t[i].id + " " + t[i + 1].id);
found = true;
break;
}
}
}
if (!found) out.println(0);
}else out.println(0);
}
public static void main(String[] args) throws IOException {
new CF27C().runIO();
}
static class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/**
* call this method to initialize reader for InputStream
*/
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/**
* get next word
*/
static String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
static String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static long[] nextLongArray(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
static int[] nextIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
}
}
| Java | ["5\n67 499 600 42 23", "3\n1 2 3", "3\n2 3 1"] | 2 seconds | ["3\n1 3 5", "0", "3\n1 2 3"] | null | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 652c7852f1d0bab64ffd2219af4f59da | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | 1,900 | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | standard output | |
PASSED | bc25fd07c8b5207a67b26a4a1f65c75b | train_001.jsonl | 1284130800 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | 256 megabytes | import java.io.*;
import java.util.*;
/**
* Created by peacefrog on 12/4/15.
* Time : 9:57 PM
*/
public class CF27C {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
PrintWriter out;
long timeBegin, timeEnd;
public void runIO() throws IOException {
timeBegin = System.currentTimeMillis();
InputStream inputStream;
OutputStream outputStream;
if (ONLINE_JUDGE) {
inputStream = System.in;
Reader.init(inputStream);
outputStream = System.out;
out = new PrintWriter(outputStream);
} else {
inputStream = new FileInputStream("/home/peacefrog/Dropbox/IdeaProjects/Problem Solving/input");
Reader.init(inputStream);
out = new PrintWriter(System.out);
}
solve();
out.flush();
out.close();
timeEnd = System.currentTimeMillis();
System.err.println("Time = " + (timeEnd - timeBegin));
}
/*
* Start Solution Here
*/
class Node implements Comparable<Node>{
int id , val;
public Node(int id, int val) {
this.id = id;
this.val = val;
}
@Override
public int compareTo(Node o) {
return Integer.compare(val , o.val);
}
}
private void solve() throws IOException {
int n = Reader.nextInt(); //This Variable default in Code Template
int arr[] = Reader.nextIntArray(n);
ArrayList<Node> s = new ArrayList<>();
int last = 0;
s.add(new Node(1 , arr[0]));
for (int i = 1; i < n; i++) {
if(arr[i] == arr[last]) continue;
s.add(new Node(i+1 , arr[i]));
last = i;
}
boolean found = false ;
Node[] t = new Node[s.size()];
t =s.toArray(t);
if(n > 2) {
for (int i = 1; i < t.length - 1; i++) {
if ((t[i + 1].val < t[i].val) && (t[i].val > t[i - 1].val)) {
out.println(3);
out.println(t[i - 1].id + " " + t[i].id + " " + t[i + 1].id);
found = true;
break;
}
if ((t[i + 1].val > t[i].val) && (t[i].val < t[i - 1].val)) {
out.println(3);
out.println(t[i - 1].id + " " + t[i].id + " " + t[i + 1].id);
found = true;
break;
}
}
if (!found) out.println(0);
}else out.println(0);
}
public static void main(String[] args) throws IOException {
new CF27C().runIO();
}
static class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/**
* call this method to initialize reader for InputStream
*/
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/**
* get next word
*/
static String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
static String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static long[] nextLongArray(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
static int[] nextIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
}
} | Java | ["5\n67 499 600 42 23", "3\n1 2 3", "3\n2 3 1"] | 2 seconds | ["3\n1 3 5", "0", "3\n1 2 3"] | null | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 652c7852f1d0bab64ffd2219af4f59da | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | 1,900 | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | standard output | |
PASSED | ec9809a1ce9f4bd3ffbd596911ac454b | train_001.jsonl | 1284130800 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
import java.util.TreeSet;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Erasyl Abenov
*
*
*/
public class Main {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
try (PrintWriter out = new PrintWriter(outputStream)) {
TaskB solver = new TaskB();
solver.solve(1, in, out);
}
}
}
class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException{
int n = in.nextInt();
int a[] = new int[n];
for(int i = 0; i < n; ++i){
a[i] = in.nextInt();
}
int f = -1;
int s = -1;
for(int i = 1; i < n; ++i){
if(f < 0 && a[i] > a[i - 1]) f = i;
if(s < 0 && a[i] < a[i - 1] ) s = i;
}
if(f < 0 || s < 0){
out.println(0);
return;
}
out.println(3);
if(f > s){
int t = f;
f = s;
s = t;
}
out.println(f + " " + s + " " + (s + 1));
}
}
class InputReader {
private final BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(nextLine());
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public BigInteger nextBigInteger(){
return new BigInteger(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
} | Java | ["5\n67 499 600 42 23", "3\n1 2 3", "3\n2 3 1"] | 2 seconds | ["3\n1 3 5", "0", "3\n1 2 3"] | null | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 652c7852f1d0bab64ffd2219af4f59da | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | 1,900 | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | standard output | |
PASSED | 52f5f11a3713677d17822aff29560990 | train_001.jsonl | 1284130800 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | 256 megabytes | import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
/*
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
*/
public class Main {
private static BufferedReader br;
private static StringTokenizer st;
private static PrintWriter pw;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
//int qq = 1;
int qq = Integer.MAX_VALUE;
//int qq = readInt();
outer: for(int casenum = 1; casenum <= qq; casenum++) {
int n = readInt();
int[] list = new int[n];
for(int i = 0; i < n; i++) {
list[i] = readInt();
}
int[] minL = new int[n];
int[] maxL = new int[n];
minL[0] = maxL[0] = list[0];
for(int i = 1; i < n; i++) {
minL[i] = Math.min(minL[i-1], list[i]);
maxL[i] = Math.max(maxL[i-1], list[i]);
}
int[] minR = new int[n];
int[] maxR = new int[n];
minR[n-1] = maxR[n-1] = list[n-1];
for(int i = n-2; i >= 0; i--) {
minR[i] = Math.min(minR[i+1], list[i]);
maxR[i] = Math.max(maxR[i+1], list[i]);
}
for(int i = 1; i < n-1; i++) {
if(minL[i-1] < list[i] && minR[i+1] < list[i]) {
pw.println(3);
int a = i-1;
int b = i+1;
while(list[a] >= list[i]) a--;
while(list[b] >= list[i]) b++;
pw.println((a+1) + " " + (i+1) + " " + (b+1));
continue outer;
}
if(maxL[i-1] > list[i] && maxR[i+1] > list[i]) {
pw.println(3);
int a = i-1;
int b = i+1;
while(list[a] <= list[i]) a--;
while(list[b] <= list[i]) b++;
pw.println((a+1) + " " + (i+1) + " " + (b+1));
continue outer;
}
}
pw.println(0);
}
exitImmediately();
}
private static void exitImmediately() {
pw.close();
System.exit(0);
}
private static long readLong() throws IOException {
return Long.parseLong(nextToken());
}
private static double readDouble() throws IOException {
return Double.parseDouble(nextToken());
}
private static int readInt() throws IOException {
return Integer.parseInt(nextToken());
}
private static String nextLine() throws IOException {
if(!br.ready()) {
exitImmediately();
}
st = null;
return br.readLine();
}
private static String nextToken() throws IOException {
while(st == null || !st.hasMoreTokens()) {
if(!br.ready()) {
exitImmediately();
}
st = new StringTokenizer(br.readLine().trim());
}
return st.nextToken();
}
}
| Java | ["5\n67 499 600 42 23", "3\n1 2 3", "3\n2 3 1"] | 2 seconds | ["3\n1 3 5", "0", "3\n1 2 3"] | null | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 652c7852f1d0bab64ffd2219af4f59da | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | 1,900 | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | standard output | |
PASSED | d3e00a52e0267058f4989c5566d70da9 | train_001.jsonl | 1284130800 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | 256 megabytes |
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;
import java.util.Vector;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n =sc.nextInt();
int[]array = new int[n];
Vector<Integer>v = new Vector<Integer>();
for(int i = 0 ; i < n ;++i)array[i]=sc.nextInt();
boolean f=false,f2=false;
for(int i = 1 ; i <array.length;++i)
{
if(array[i-1]<array[i]&&!f)
{
v.add(i);
v.add(i+1);
f=true;
}
if(array[i-1]>array[i]&&!f2)
{
v.add(i);
v.add(i+1);
f2=true;
}
}
if(!f||!f2)
{
System.out.println(0);
}
else{
System.out.println(3);
System.out.print(v.elementAt(0)+" "+v.elementAt(2)+" "+v.elementAt(3));
}
}
}
| Java | ["5\n67 499 600 42 23", "3\n1 2 3", "3\n2 3 1"] | 2 seconds | ["3\n1 3 5", "0", "3\n1 2 3"] | null | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 652c7852f1d0bab64ffd2219af4f59da | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | 1,900 | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | standard output | |
PASSED | aa8298b0c5aa2bed2e8dac6aa5f06c77 | train_001.jsonl | 1284130800 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | 256 megabytes | import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Zyflair Griffane
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
PandaScanner in = new PandaScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
C solver = new C();
solver.solve(1, in, out);
out.close();
}
}
class C {
public void solve(int testNumber, PandaScanner in, PrintWriter out) {
int n = in.nextInt();
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}
int minIdx = 0;
int maxIdx = 0;
for (int i = 1; i < n; i++) {
int a = Math.min(minIdx, maxIdx);
int b = Math.max(minIdx, maxIdx);
if ((arr[a] <= arr[b] && arr[b] <= arr[i]) || (arr[a] >= arr[b] && arr[b] >= arr[i])) {
if (arr[i] < arr[minIdx]) {
minIdx = i;
}
if (arr[i] > arr[maxIdx]) {
maxIdx = i;
}
}
else {
out.println("3");
out.printf("%d %d %d\n", a + 1, b + 1, i + 1);
return;
}
}
out.println("0");
}
}
class PandaScanner {
public BufferedReader br;
public StringTokenizer st;
public InputStream in;
public PandaScanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(this.in = in));
}
public String nextLine() {
try {
return br.readLine();
}
catch (Exception e) {
return null;
}
}
public String next() {
if (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(nextLine().trim());
return next();
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
| Java | ["5\n67 499 600 42 23", "3\n1 2 3", "3\n2 3 1"] | 2 seconds | ["3\n1 3 5", "0", "3\n1 2 3"] | null | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 652c7852f1d0bab64ffd2219af4f59da | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | 1,900 | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | standard output | |
PASSED | 358bb79fdfde936838511f1cf60c1487 | train_001.jsonl | 1284130800 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String [] args){
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int array[]=new int[n+1];
for(int i=1;i<=n;i++)array[i]=in.nextInt();
int left[]=new int[n+1];
int right[]=new int[n+1];
Arrays.fill(left,-1);
Arrays.fill(right,-1);
int min=Integer.MAX_VALUE;
int max=Integer.MIN_VALUE;
int posMin=0;
int posMax=0;
for(int i=1;i<=n;i++){
min=Math.min(min,array[i]);
max=Math.max(max,array[i]);
if(array[i] < array[posMax] && posMax > posMin || array[i] > array[posMin] && posMax < posMin){
System.out.println("3");
System.out.print(Math.min(posMin,posMax)+" "+Math.max(posMin,posMax)+" "+i);
return;
}
if(min==array[i])posMin=i;
if(max==array[i])posMax=i;
}
System.out.print("0");
}
}
| Java | ["5\n67 499 600 42 23", "3\n1 2 3", "3\n2 3 1"] | 2 seconds | ["3\n1 3 5", "0", "3\n1 2 3"] | null | Java 7 | standard input | [
"constructive algorithms",
"greedy"
] | 652c7852f1d0bab64ffd2219af4f59da | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | 1,900 | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | standard output | |
PASSED | d7d7c928b46b1e8f457ddb9875f7a1b7 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | //package goku;
import java.io.*;
import java.util.*;
public class goku {
BufferedReader br;
PrintWriter out;
long mod = (long) (1e9 + 7), inf = (long) (5e18);
void spiritBomb() {
int t = ni();
while(t-- > 0) {
double n = nd() * 2;
double radius = 1.0 / (2 * Math.tan(Math.PI / n));
out.println(2 * radius);
}
}
int gcd(int a, int b) {
if(b == 0) return a;
return gcd(b, a % b);
}
long mp(long b, long e) {
long r = 1;
while(e > 0) {
if( (e&1) == 1 ) r = (r * b) % mod;
b = (b * b) % mod;
e >>= 1;
}
return r;
}
// -------- I/O Template -------------
char nc() {
return ns().charAt(0);
}
String nLine() {
try {
return br.readLine();
} catch(IOException e) {
return "-1";
}
}
double nd() {
return Double.parseDouble(ns());
}
long nl() {
return Long.parseLong(ns());
}
int ni() {
return Integer.parseInt(ns());
}
StringTokenizer ip;
String ns() {
if(ip == null || !ip.hasMoreTokens()) {
try {
ip = new StringTokenizer(br.readLine());
} catch(IOException e) {
throw new InputMismatchException();
}
}
return ip.nextToken();
}
void kamehameha() {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
spiritBomb();
out.flush();
}
public static void main(String[] args) {
new goku().kamehameha();
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 75fe30ad2bf95e23b6608b97d2651283 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.util.*;
public class Solution{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
double s=2*0.5/(Math.tan(Math.PI/(2*n)));
System.out.printf("%.9f\n",s);
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | d0c49e902af8d206a4c04cb4dd45b146 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
/*
procrastinating
*/
public class Main {
static FastReader in;
static PrintWriter out;
static Random rand = new Random();
static final int INF = (int) (1e9 + 10);
static final int MOD = (int) (998244353);
static void solve() {
int t = in.nextInt();
for (int tt = 0; tt < t; tt++) {
int n = in.nextInt();
double r = 0.5 / Math.sin(Math.toRadians(90.0 / n));
double res = Math.sqrt(r * r * 4 - 1);
out.println(res);
}
}
public static void main(String[] args) throws FileNotFoundException {
in = new FastReader(System.in);
// in = new FastReader(new FileInputStream("sometext.txt"));
out = new PrintWriter(System.out);
// out = new PrintWriter(new FileOutputStream("output.txt"));
solve();
// Thread thread = new Thread(null, () -> {
// solve();
// });
// thread.start();
// try {
// thread.join();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// out.flush();
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
Integer nextInt() {
return Integer.parseInt(next());
}
Long nextLong() {
return Long.parseLong(next());
}
Double nextDouble() {
return Double.parseDouble(next());
}
String next() {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(nextLine());
}
return st.nextToken();
}
String nextLine() {
String s = "";
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return s;
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 0598cf6dc5ab5ce958b1e1218be87e87 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | //package CodeForces;
import java.util.Scanner;
public class SimplePolyGonEmbedding {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int t=s.nextInt();
StringBuilder temp=new StringBuilder();
while(t>0)
{
double n=s.nextDouble();
double angle=((360/(2*n)))/2;
//System.out.println(angle);
angle=Math.toRadians(angle);
double ans=1/Math.tan(angle);
//System.out.println(angle);
temp.append(ans);temp.append("\n");
t--;
}
System.out.println(temp);
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | d9af0cd242a9c384851427de3c401137 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | //package CodeForces;
import java.util.Scanner;
public class SimplePolyGonEmbedding {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t>0)
{
double n=s.nextDouble();
double angle=((360/(2*n)))/2;
//System.out.println(angle);
angle=Math.toRadians(angle);
double ans=1/Math.tan(angle);
//System.out.println(angle);
System.out.println(ans);
t--;
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | d36a62e2bd638bc37c7e221f4978602a | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.List;
public class SimplePolygonEmbedding { // Template for CF
public static class ListComparator implements Comparator<List<Integer>> {
@Override
public int compare(List<Integer> l1, List<Integer> l2) {
for (int i = 0; i < l1.size(); ++i) {
if (l1.get(i).compareTo(l2.get(i)) != 0) {
return l1.get(i).compareTo(l2.get(i));
}
}
return 0;
}
}
public static void main(String[] args) throws IOException {
// Check for int overflow!!!!
// Should you use a long to store the sum or smthn?
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int T = Integer.parseInt(f.readLine());
for (int i = 0; i < T; i++) {
int a = Integer.parseInt(f.readLine()) * 2;
double ang = (360) + (a - 4) * 180;
ang /= 180;
ang *= Math.PI;
ang /= a;
ang /= 2;
double sum = Math.tan(ang);
out.println(sum);
}
out.close();
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | ec70c97a96f3365152b4414120de3260 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
StringBuilder str = new StringBuilder();
while(t != 0) {
solve(sc.nextDouble());
// str.append() + "\n");
t--;
}
//System.out.println(str.toString());
}
public static void solve(double n) {
StringBuilder str = new StringBuilder();
double length = 2.0 * n;
double angle = (Math.PI) / length;
double output = 1/ Math.tan(angle);
System.out.println(output);
// str.append(output);
// return str.toString();
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 570ead856916ac80bd5108ce960d3d5a | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
StringBuilder str = new StringBuilder();
while(t != 0) {
str.append(solve(sc.nextDouble()) + "\n");
t--;
}
System.out.println(str.toString());
}
public static String solve(double n) {
StringBuilder str = new StringBuilder();
double length = 2.0 * n;
double angle = (Math.PI) / length;
double output = 1/ Math.tan(angle);
str.append(output);
return str.toString();
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 6e36270f0fae4732302d080f63ae44ca | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.Scanner;
import java.text.NumberFormat;
import java.math.RoundingMode;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC1 solver = new TaskC1();
solver.solve(1, in, out);
out.close();
}
static class TaskC1 {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int t = in.nextInt();
DecimalFormat df = new DecimalFormat("#.########");
df.setRoundingMode(RoundingMode.HALF_EVEN);
for (int i = 0; i < t; i++) {
int n = in.nextInt();
int n_2 = 2 * n;
if (n == 2) {
out.println(df.format(1 * 1.000000000));
} else {
double angle = (Math.PI / (2.00000000000 * n));
String angleS = df.format(angle);
Double sss = Double.parseDouble(angleS);
double sinV = Math.tan(sss);
double ans = 1.00000000 / sinV;
/// area of polygon
// double area = (2*n) / (4.0 * Math.tan((Math.PI / 2*n)));
out.println(df.format(ans));
}
}
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 4e3722f1df621094855e23bc92940604 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.text.DecimalFormat;
import java.util.*;
public class Problem
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
DecimalFormat df = new DecimalFormat("#.##########");
if(n==2)
System.out.printf("%.9f %n",1.0);
else
{
double angle = 360.0 / (4*n);
double ans = 1.0 / Math.tan(Math.toRadians(angle));
System.out.println(df.format(ans));
}
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | b9685e46ced6bbd2e4e7615abe81afcc | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
public class Codec
{
public static void main(String []args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int tc=Integer.parseInt(br.readLine());
while(tc>0)
{tc--;
int n=Integer.parseInt(br.readLine());
n=2*n;
double angle=2*Math.acos(0);
System.out.format("%.9f\n",(1/((Math.tan(angle/n)))));
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 9e77a9c381a0b343a2231060a6e6952e | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.stream.*;
import static java.util.stream.Collectors.*;
public class Main {
void solve() {
int n = 2*in.nextInt();
int m = (n - 1) / 4;
double alpha = Math.PI - Math.PI * (n - 2) / n;
double tmp = 1;
for (int i = 0; i < m; i++) {
tmp += 2 * Math.cos(alpha * (i + 1));
}
out.println(tmp);
}
static final boolean MULTI_TEST = true;
// --------------------------------------------------------------------------------------------------------------
// --------------------------------------------------HELPER------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------
void solve2() {
// init();
if (MULTI_TEST) {
int t = in.nextInt();
for (int i = 0; i < t; i++) {
solve();
}
} else {
solve();
}
}
// --------------------ALGORITHM-------------------------
public void sort(int[] arr) {
List<Integer> tmp = Arrays.stream(arr).boxed().sorted().collect(Collectors.toList());
for (int i = 0; i < arr.length; i++) {
arr[i] = tmp.get(i);
}
}
// --------------------SCANNER-------------------------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner(boolean debug) {
if (debug) {
try {
br = new BufferedReader(new FileReader("input.txt"));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
} else {
br = new BufferedReader(new InputStreamReader(System.in));
}
}
String next() {
while (st == null || !st.hasMoreElements()) {
st = new StringTokenizer(nextLine());
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] nextInts(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
long nextLong() {
return Long.parseLong(next());
}
public long[] nextLongs(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
try {
String line = br.readLine();
if (line == null) {
throw new RuntimeException("empty line");
}
return line;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
// --------------------WRITER-------------------------
public static class MyWriter extends PrintWriter {
public MyWriter(OutputStream out) {
super(out);
}
void println(int[] arr) {
String line = Arrays.stream(arr).mapToObj(String::valueOf).collect(joining(" "));
println(line);
}
}
// --------------------MAIN-------------------------
public MyScanner in;
public MyWriter out;
public static void main(String[] args) {
Main m = new Main();
m.in = new MyScanner(args.length > 0);
m.out = new MyWriter(new BufferedOutputStream(System.out));
m.solve2();
m.out.close();
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | ccabc98c9d4f80f203785d4cb884fa32 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes |
import java.math.*;
import java.util.*;
public class asol {
public static double tan(double sides) {
double k = 180.0/sides;
double a = Math.toRadians(k);
return Math.tan(a);
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int tc = scan.nextInt();
while(tc--!=0) {
int n = scan.nextInt();
System.out.printf("%.6f",(1.0/tan(2*n)));
System.out.println();
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | cb0d11d3603e8d071b14b01beb000164 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Mai
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t!=0)
{int n=sc.nextInt();
int n1=2*n;
double r=180.0/n1;double p=3.14159265;
double t1=Math.tan(r*p/180.0);
double ans=1.0/t1;
System.out.println(ans);t--;
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 5b98f3e2d6047b30d5d3e63d15382ec9 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.lang.Math;
public class Solution{
public static void main(String[] args) throws Exception{
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = fs.nextInt();
while(t-->0) {
int n = fs.nextInt();
double d = (double)180;
d = Math.toRadians(d);
out.println(String.format("%.9f",1/Math.tan(d/(2*n))));
}
out.close();
}
static class FastScanner{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String next(){
while(!st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
} catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt(){
return Integer.parseInt(next());
}
public int[] readArray(int n){
int[] a = new int[n];
for(int i=0;i<n;i++)
a[i] = nextInt();
return a;
}
public long nextLong() {
return Long.parseLong(next());
}
}
static int lowerBound(int[] arr, int l, int r, int k) {
while(r>l) {
int mid = (l+r)/2;
if(arr[mid]>=k) {
r = mid;
}
else {
l = mid+1;
}
}
if(arr[l]<k)
return -1;
return l;
}
static int upperBound(int[] arr, int l, int r, int k) {
while(r>l) {
int mid = (l+r)/2;
if(arr[mid]>k) {
r = mid;
}
else {
l = mid+1;
}
}
if(arr[l]<=k)
return -1;
return l;
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 4e620bfd9c98098a754e3cb821c1c3d7 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.util.*;
import java.io.*;
import java.io.BufferedReader;
public class Z_C{
public static final String TASKNAME = "";
public static final long mod= 1000000007;
public static void main(String[] args) throws IOException {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
// InputReader in = new InputReader(new FileInputStream(TASKNAME+".in"));
// PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(TASKNAME+".out")));
Autocompletion solver = new Autocompletion();
solver.solve(1, in, out);
out.close();
}
static class Autocompletion {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int t=in.nextInt();
for(int z=0;z<t;z++) {
int n=in.nextInt()*2;
double arr[]=new double[n];
arr[1]=1.0;
for(int i=2;i<=n/4;i++) {
arr[i]=getSideB(Math.PI*(double)(n-i)/(double)n,1.0,arr[i-1]);
}
double ans=get(n,n/2);
ans=get(n,n/2-1);
if(n%8==0) {
ans=get(n,n/2-1);
}
System.out.println(ans);
}
}
private double get(int n,int i) {
if(i==1) {
return 1;
}
if(i%2==0) {
return getSideB(Math.PI*(double)(n-i)/(double)n,get(n,i/2),get(n,i/2));
}
return getSideB(Math.PI*(double)(n-i)/(double)n,get(n,i-1),get(n,1));
}
public static double getSideB(double d, double e, double arr) {
return (double) Math.sqrt(Math.pow(e, 2) + Math.pow(arr, 2) - 2 * e * arr * Math.cos(d));
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] nextIntArr(int n) {
int arr[]=new int[n];
for(int i=0;i<n;i++) {
arr[i]=this.nextInt();
}
return arr;
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 6993d0ef5f5ef576bc8a1fbadb2229bc | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SimplePolygonEmbedding {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while (t-->0){
int n = Integer.parseInt(br.readLine());
double x = Math.toRadians(180.0/n);
int k =n/2;
double s = ((Math.sin(((2*k+1)*x)/2)/(2*Math.sin(x/2)))*2);
System.out.println(s);
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | d42a957d42a04837d7f77d1757dcb022 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.util.*;
import java.io.*;
public class cf645 {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine().trim());
while(t-->0) {
// String str=br.readLine().trim();
// char ch[]=str.toCharArray();
// int c1=0,c2=0,c3=0,min=Integer.MAX_VALUE;
// for(char c:ch) {
// if(c=='1')c1++;
// else if(c=='2')c2++;
// else c3++;
// }
// if(c1==0 || c2==0||c3==0) {
// System.out.println("0");
// }else {
// int b=0,c=0;
// for(int i=0;i<str.length();i++){
// if(ch[i]=='1') {
// b=str.indexOf('2',i+1);
// c=str.indexOf('3',i+1);
// }else if(ch[i]=='2') {
// b=str.indexOf('1',i+1);
// c=str.indexOf('3',i+1);
// }else {
// b=str.indexOf('1',i+1);
// c=str.indexOf('2',i+1);
// }
// if(b==-1 || c==-1)break;
// int p=Math.max(b, c);
// min=Math.min(min, p-i+1);
// }
// System.out.println(min);
// }
int n=Integer.parseInt(br.readLine().trim());
double r=Math.toRadians(90.0/n);
double tan=Math.tan(r);
double h=1/(tan);
// double ans=1/tan;
System.out.println(h);
// double th=Math.toRadians(360.0/(4*n));
// double tan=Math.tan(th);
// double h=1/(2*tan);
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 2cc0751597fce7517d0723ae3d9f2d15 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class Simple_Polygon_Embedding
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static long binary(long x)
{
long left=0;
long right=1000000;
long ans=0;
while(left<=right)
{
long mid=(left+right)/2;
long temp=mid*(3*mid+1)/2;
if(temp<=x)
{
ans=temp;
left=mid+1;
}
else
{
right=mid-1;
}
}
return ans;
}
public static void main(String[] args)
{
FastReader sc=new FastReader();
PrintWriter pw=new PrintWriter(System.out);
int t1=sc.nextInt();
m:while(t1-->0)
{
double n=sc.nextDouble();
pw.println(1/Math.tan(Math.PI/2/n));
}
pw.flush();
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | d48f6e4fb3f0d79c36e029f20c16e848 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class q3 {
public static void main(String[] args) {
FastReader s = new FastReader();
int t = s.nextInt();
while(t-- > 0)
{
int n = s.nextInt();
System.out.println(Math.tan((Math.PI*(2*n-2))/(double)(4*n)));
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 6bc4db3ac5d2233c8cfa2054f73158d4 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class a
{
static final int mod = 1000000007;
public static void main (String[] args) throws java.lang.Exception
{
FastReader sc = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-->0) {
int n = sc.nextInt();
double a = (double)(2*n-2)*45/n;
double b = Math.toRadians(a);
out.println(Math.tan(b));
}
out.flush();
}
}
class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 90a96d3cd4594b5617245431b1cb6460 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
// written by luchy0120
public class Main {
public static void main(String[] args) throws Exception {
new Main().run();
}
void solve() {
// println(1<<30);
//it
int t = ni();
for(int i=0;i<t;++i){
int n = ni();
double pi = Math.PI;
double theta = pi/(2*n);
double f = 1.0/Math.tan(theta);
println(f);
}
}
double dis(long x,long y,long a,long b){
long v = (x-a)*(x-a)+(y-b)*(y-b);
return Math.sqrt(v);
}
InputStream is;
PrintWriter out;
void run() throws Exception {
//is = new FileInputStream(new File("C:\\Users\\Luqi\\Downloads\\P3387_9.in"));
is = System.in;
out = new PrintWriter(System.out);
solve();
out.flush();
}
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private char ncc() {
int b = readByte();
return (char) b;
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private String nline() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!isSpaceChar(b) || b == ' ') {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[][] nm(int n, int m) {
char[][] a = new char[n][];
for (int i = 0; i < n; i++) a[i] = ns(m);
return a;
}
private int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ni();
return a;
}
private long[] nal(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nl();
return a;
}
private int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
}
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
else return minus ? -num : num;
b = readByte();
}
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
}
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') num = num * 10 + (b - '0');
else return minus ? -num : num;
b = readByte();
}
}
void print(Object obj) {
out.print(obj);
}
void println(Object obj) {
out.println(obj);
}
void println() {
out.println();
}
void printArray(int a[],int from){
int l = a.length;
for(int i=from;i<l;++i){
print(a[i]);
if(i!=l-1){
print(" ");
}
}
println();
}
void printArray(long a[],int from){
int l = a.length;
for(int i=from;i<l;++i){
print(a[i]);
if(i!=l-1){
print(" ");
}
}
println();
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | c678777ce0ea74ddaadc8e5e279e9052 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main
{
public static void main(String[] args) {
new Thread(null, new Runnable() {
public void run() {
solve();
}
}, "1", 1 << 26).start();
}
static void solve () {
FastReader fr =new FastReader(); PrintWriter op =new PrintWriter(System.out);
int t =fr.nextInt() ; double n ,a ,b ,c ;
while (t-->0) {
n =(double)fr.nextInt() ; a =Math.PI/n ; b =Math.PI*(n-1.0) / n ;
c =(1.0 - Math.cos(b)) / (1.0 - Math.cos(a)) ;
c =Math.sqrt(c) ; op.println(c) ;
}
op.flush(); op.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br =new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st==null || (!st.hasMoreElements()))
{
try
{
st =new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
String str ="";
try
{
str =br.readLine();
}
catch(IOException e)
{
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next()) ;
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | da97d813eca43e9cae3c6d31286025e6 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class E87_C1 implements Runnable{
public static void main(String[] args) {
new Thread(null, new E87_C1(),"Main",1<<27).start();
}
@Override
public void run() {
FastReader fd = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = fd.nextInt();
for(int te = 0; te < t; te++){
int n = fd.nextInt();
double apothem = (1 / (Math.tan((Math.PI / (n*2)))));
out.println(apothem);
}
out.close();
}
//Helper functions
static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
static int lcm(int a, int b) {
return (a*b)/gcd(a, b);
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | d5193f3ea9013e70f976a7b51bc2fc7c | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes |
import java.util.*;
public class codfo {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-->0){
int n = s.nextInt();
double ans = 1 / (Math.tan(Math.PI/(2*n)));
System.out.println(ans);
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | f81c8e40861fdb4326c7cab717f8d28c | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class Main implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public int nextInt()
{
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.')
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception
{
new Thread(null, new Main(),"Main",1<<27).start();
}
public void run(){
InputReader sc=new InputReader(System.in);
PrintWriter out=new PrintWriter(System.out);
int t=sc.nextInt();
for(int h=0;h<t;h++)
{
int n=sc.nextInt();
n=2*n;
double angle=180*(n-2);
angle=angle/n;
double angle1=angle/2;
double add=1*Math.tan(Math.toRadians(angle1));
out.println(add);
}
out.flush();
out.close();
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 3f66cab6443b08c6a80bea45dc042beb | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution{
static int llllll=0;
static long mod=998244353 ;
static boolean f=true;
static class pair implements Comparable<pair>{
int a,b,c;
pair(int x,int y,int z){
a=x;b=y;c=z;
}
public int compareTo(pair t){
if(c<t.c) return 1;
else if(c==t.c)
{ if(a<t.a) return -1;
else if(a>t.a) return 1;
else return 0;
}
else return -1;
}
}
// public static ArrayList<pair> bfs(String[] a,int r,int c){
// ArrayList<pair> ans=new ArrayList<>();
// Queue<pair> q=new LinkedList<>();
// int[][] dxy={{-1,0,1,0},{0,-1,0,1}};
// q.add(new pair(r,c));
// HashSet<String> h=new HashSet<>();
// while(!q.isEmpty()){
// pair f=q.poll();
// ans.add(f);h.add(f.a+" "+f.b);
// for(int i=0;i<4;i++){
// int dx=f.a+dxy[0][i];
// int dy=f.b+dxy[1][i];
// if(dx<0||dy<0||dx>=a.length||dy>=a.length||h.contains(dx+" "+dy)||
// a[dx].charAt(dy)=='1')
// continue;
// q.add(new pair(dx,dy));
// h.add(dx+" "+dy);
// }
// }
// return ans;
// }
/*
1 1 1 1 1
3 3 3
2 3 3 2 1 3
1
2 2 2 2
4 4 4 1 4
*/
public static int pow(int a, int n) {
long ans = 1;
long base = a;
while (n != 0) {
if ((n & 1) == 1) {
ans *= base;
ans %= 1000000007;
}
base = (base * base) % 1000000007;
n >>= 1;
}
return (int) ans % 1000000007;
}
public static int find(int x){
int i=1;int f=0;
while(x>0){
if((x&1)==0)f=i;
x>>=1;i++;
}
return f;
}
public static boolean good(int x){
if((((x+1)&x))==0)
return true;
return false;
}
public static long f(long n){
long val=2;
long preval=0;int i=1;
while(n>=val){
i++;
preval=val;
val=3*i+val-1;
}
return preval;
}
public static boolean bfs(ArrayList<Integer>[] a,int n,int[] b){
Queue<Integer> p=new LinkedList<>();
boolean v[]=new boolean[n];
v[0]=true;int k=0;
if(b[0]!=0)return false;
p.add(0);int c=1;
HashSet<Integer> h=new HashSet<Integer>();
h.add(0);
while(!p.isEmpty()){
int f=p.poll();k++;
if(h.contains(f))h.remove(f);
else return false;
v[f]=true;
c--;
for(int i:a[f]){
if(!v[i]){
p.add(i);v[i]=true;}
}
if(c==0){
c=p.size();
if(h.size()!=0)return false;
for(int j=k;j<k+p.size();j++)
h.add(b[j]);
}
}
return true;
}
public static int mi(int[] a,int k,int[] dp,int n){
int max=0;
for(int i=1;i*i<=k;i++){
// System.out.println("fact "+i);
if(k%i==0&&(a[i-1]<a[k-1])){
// System.out.println(i+" "+dp[i-1]+" "+a[i-1]+" ");
max=Math.max(dp[i-1],max);}
if(k%i==0&&(a[k/i-1]<a[k-1])){
// System.out.println(i+" "+dp[i-1]+" "+a[i-1]+" ");
max=Math.max(dp[k/i-1],max);}
}
return max;
}
public static void dfs(ArrayList<Integer> a[],boolean[] v,int n,int llllll){
v[n]=true;
llllll=Math.max(n,llllll);
// System.out.println(max);
for(int i=0;i<a[n].size();i++){
if(!v[a[n].get(i)]){
dfs(a,v,a[n].get(i),llllll);
}
}
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
StringBuilder st=new StringBuilder();
while(t-- > 0) {
int n = s.nextInt() * 2;
st.append((Math.tan(Math.PI * (n - 2) / n / 2))+"\n");
}
System.out.println(st);
/*
2
1
3
1
6
6 23 21
1 1000 0
2 1 2
0
40
41664916690999888
1
1 2
2 1 3
3 1 2 4
2 4 1 3 5
3 4 1 5 2 6
1 11
5 35
3 6
0 42
0 0
1 2
3 4
6 45 46
2 2 1
3 4 2
4 4 3
*/
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 9ae48d848be66e304e4e2a36bb4a6db8 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.util.Scanner;
public class SimplePolygonEmbedding {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T-->0){
double n = sc.nextDouble()*2;
System.out.println(Math.tan(Math.PI*(n-2)/n/2));
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 6a59a281cb240258d536d46e54b56b30 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | //package Education87;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
public class typeC {
public static void main(String[] args) {
FastReader s = new FastReader();
int T = s.nextInt();
for(int t=0;t<T;t++) {
int n = s.nextInt()*2;
double pi = 180;
pi = Math.toRadians(pi);
double a = n-2;
a = (a/(double)n)*0.5;
a = a*Math.PI;
// double a = (double)1/(double)(2*Math.tan(pi/n));
// System.out.println("a: "+a);
// double r2 = (1/(double)2)*(1/(double)2) + a*a;
double r = Math.tan(a);
System.out.println(r);
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | ef7c123cfd1315ef553c80dc15301230 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | // package Education87;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
public class typeC {
public static void main(String[] args) {
FastReader s = new FastReader();
int T = s.nextInt();
for(int t=0;t<T;t++) {
int n = s.nextInt()*2;
double ang1 = 90*(n-2)/(double)n;
double ang1R = Math.toRadians(ang1);
double ans = Math.tan(ang1R);
System.out.println(ans);
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 1ed2835b2af73793acc1704b40d38e89 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class SimplePolygonEmbedding {
static PrintWriter pw;
static class FastReader {
private InputStream mIs;
private byte[] buf = new byte[1024];
private int curChar, numChars;
public FastReader() {
this(System.in);
}
public FastReader(InputStream is) {
mIs = is;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = mIs.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long l() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int i() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public double d() throws IOException {
return Double.parseDouble(next());
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public void scanIntArr(int[] arr) {
for (int li = 0; li < arr.length; ++li)
arr[li] = i();
}
public void scanIntIndexArr(int[] arr) {
for (int li = 0; li < arr.length; ++li) {
arr[li] = i() - 1;
}
}
public void printIntArr(int[] arr) {
for (int li = 0; li < arr.length; ++li)
pw.print(arr[li] + " ");
pw.println();
}
public void printLongArr(long[] arr) {
for (int li = 0; li < arr.length; ++li)
pw.print(arr[li] + " ");
pw.println();
}
public void scanLongArr(long[] arr) {
for (int i = 0; i < arr.length; ++i) {
arr[i] = l();
}
}
public void shuffle(int[] arr) {
for (int i = arr.length; i > 0; --i) {
int r = (int) (Math.random() * i);
int temp = arr[i - 1];
arr[i - 1] = arr[r];
arr[r] = temp;
}
}
public int findMax(int[] arr) {
return Arrays.stream(arr).max().getAsInt();
}
}
public static void main(String[] args) throws IOException {
FastReader fr = new FastReader();
pw = new PrintWriter(System.out);
int i, j, n, m, temp, t;
double ans;
t = fr.i();
while (t-- > 0) {
n = fr.i();
ans = 1 / (Math.tan(Math.PI / (2 * n)));
pw.println(ans);
}
pw.flush();
pw.close();
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 5af19e95e51be37f363c243b7ab4c3b5 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.util.*;
public class q3 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int test = scan.nextInt();
while(test-->0){
int n = scan.nextInt();
if(n==2){
System.out.println("1.000000000");
continue;
}
double val = (double)360/(double)(2*n);
double r1 = 90 - (double)val/(double)2;
r1 = Math.toRadians(r1);
double a = Math.tan(r1)/2;
double r2 = 90 - val;
r2 = Math.toRadians(r2);
double b = a/(Math.tan(r2));
//System.out.println(val+" "+a+" "+b+" ");
System.out.printf("%.9f",2*a);
System.out.println();
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | ae191686f4bf66287a1ec2db71f11505 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.util.*;
public class q3 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int test = scan.nextInt();
while(test-->0){
int n = scan.nextInt();
if(n==2){
System.out.println("1.000000000");
continue;
}
double val = (double)360/(double)(2*n);
double r1 = 90 - (double)val/(double)2;
r1 = Math.toRadians(r1);
double a = Math.tan(r1)/2;
double r2 = 90 - val;
r2 = Math.toRadians(r2);
double b = a/(Math.tan(r2));
//System.out.println(val+" "+a+" "+b+" ");
System.out.println(2*a);
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | cfdc53d6f320b55c654cf37d5e18aaef | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class SimplePolygonEmbedding { //Just brute force problems with small constraints
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int T = input.nextInt();
for (int i = 1; i <= T; i++) {
double N = input.nextDouble();
N*=2;
double theta = 360.0/N;
theta/=2;
double ans = 0.5/Math.tan(Math.toRadians(theta));
ans*=2;
System.out.println(ans);
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 7c66e8fc67fa8721e53af0a6c8b4964a | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class SimplePolygonEmbedding {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int T = input.nextInt();
for (int i = 1; i <= T; i++) {
double N = input.nextDouble();
N*=2;
double theta = 360.0/N;
theta/=2;
double ans = 0.5/Math.tan(Math.toRadians(theta));
ans*=2;
System.out.println(ans);
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | e5b026b96096825b50b9122242e790ed | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Simple_Polygon_Embedding {
public static void main(String[] args) throws IOException {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String test_numS=bf.readLine();
int test_num=Integer.parseInt(test_numS);
while(test_num>0){
String T=bf.readLine();
int t=2*Integer.parseInt(T);
solve(t);
test_num--;
}
}
public static void solve(int t){
int num=(t-4)/4;
double up=0,down=0,zhijiao=Math.PI/2;
double angle=((t-2)*Math.PI)/t;
double len=1;
if (num>0){
len+=1*Math.sin(angle-zhijiao)*2;
//System.out.println("+"+1*Math.sin(angle-zhijiao)+"len"+len);
num--;
down=zhijiao-(angle-zhijiao);
}
while(num>0){
up=angle-zhijiao-down;
len+=1*Math.sin(up)*2;
down=zhijiao-up;
num--;
}
System.out.println(len);
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 186a1812da796ee86f71c769d92b9293 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
public class Main{
public static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static final int MAX_CHARS = 256;
static int findSubString(String str)
{
int n = str.length();
int dist_count = 0;
boolean[] visited = new boolean[MAX_CHARS];
Arrays.fill(visited, false);
for (int i = 0; i < n; i++) {
if (visited[str.charAt(i)] == false) {
visited[str.charAt(i)] = true;
dist_count++;
}
}
int start = 0, start_index = -1;
int min_len = Integer.MAX_VALUE;
int count = 0;
int[] curr_count = new int[MAX_CHARS];
for (int j = 0; j < n; j++) {
curr_count[str.charAt(j)]++;
if (curr_count[str.charAt(j)] == 1)
count++;
if (count == dist_count) {
while (curr_count[str.charAt(start)] > 1) {
if (curr_count[str.charAt(start)] > 1)
curr_count[str.charAt(start)]--;
start++;
}
int len_window = j - start + 1;
if (min_len > len_window) {
min_len = len_window;
start_index = start;
}
}
}
return str.substring(start_index, start_index + min_len).length();
}
public static void main(String[] args)
{
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader sc = new InputReader(inputStream);
PrintWriter w = new PrintWriter(outputStream);
long t=sc.nextLong();
while(t-->0)
{
double n=sc.nextDouble()*2;
double ans=1;
ans=(ans/Math.tan(Math.PI/n));
w.println(ans);
}
w.close();
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 962de6a6d64e3c6bffecf7805214d4f3 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int itr = Integer.parseInt(br.readLine());
while(itr-->0){
int n = 2*(Integer.parseInt(br.readLine()));
double r = 1.0/((Math.sin(Math.PI/n))*2.0);
System.out.println(2*Math.sqrt(r*r-1.0/4));
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 3b59d55d6ddd19d5720ef5cd29990665 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
static long m = (long) (1e9 + 7);
public static void main(String[] args) throws IOException {
Scanner scn = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int T = scn.nextInt(), tcs = 0;
C: while (tcs++ < T)
sb.append(1 / Math.tan(2 * Math.PI / (4 * scn.nextInt())) + "\n");
System.out.print(sb);
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | e671a5372b9da9db20b7ca3c8cdab948 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
static long m = (long) (1e9 + 7);
public static void main(String[] args) throws IOException {
Scanner scn = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int T = scn.nextInt(), tcs = 0;
C: while (tcs++ < T) {
int n = scn.nextInt();
double x = Math.PI / (2 * n), ans = Math.sin(x);
ans = 1 / ans;
double s = (Math.sqrt(ans * ans - 1.0));
sb.append(s + "\n");
}
System.out.print(sb);
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 489159d822f17a3f730ea2ab968112e4 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.LinkedBlockingDeque;
public class scratch_25 {
// int count=0;
//static long count=0;
static class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/**
* call this method to initialize reader for InputStream
*/
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/**
* get next word
*/
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
}
static class Pair implements Comparable<Pair>{
int x;
int y;
public Pair(int x,int y){
this.x=x;
this.y=y;
}
@Override
public int compareTo(Pair o){
return this.x-o.x;
}
@Override
public boolean equals(Object me) {
Pair binMe = (Pair)me;
if(this.x==binMe.x && this.y==binMe.y)
return true;
else
return false;
}
@Override
public int hashCode() {
return this.x + this.y;
}
@Override
public String toString() {
return x+" "+y;
}
}
public static void main(String[] args) throws IOException {
Reader.init(System.in);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int t= Reader.nextInt();
for (int tt = 0; tt <t ; tt++) {
double n= Reader.nextDouble();
n=2*n;
double x= 360.0/(2.0*n);
double val= Math.tan(Math.toRadians(x));
// double y=x/n;
System.out.println(1.0/val);
}
// out.flush();
// out.close();
}
public static ArrayList<Integer> Sieve(int n) {
boolean arr[]= new boolean [n+1];
Arrays.fill(arr,true);
arr[0]=false;
arr[1]=false;
for (int i = 2; i*i <=n ; i++) {
if(arr[i]){
for (int j = 2; j <=n/i ; j++) {
int u= i*j;
arr[u]=false;
}}
}
ArrayList<Integer> ans= new ArrayList<>();
for (int i = 0; i <n+1 ; i++) {
if(arr[i]){
ans.add(i);
}
}
return ans;
}
static long power( long x, long y, long p)
{
long res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0)
{
if((y & 1)==1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
public static long ceil_div(long a, long b){
return (a+b-1)/b;
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b)
{
return (a*b)/gcd(a, b);
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 3780af90c3c9d440e75c959e398e7681 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
public class TestClass {
public static void main(String args[] ) throws Exception {
/* Sample code to perform I/O:
* Use either of these methods for input
//BufferedReader
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String name = br.readLine(); // Reading input from STDIN
System.out.println("Hi, " + name + "."); // Writing output to STDOUT
//Scanner
Scanner s = new Scanner(System.in);
String name = s.nextLine(); // Reading input from STDIN
System.out.println("Hi, " + name + "."); // Writing output to STDOUT
*/
// Write your code here
StringBuffer str = new StringBuffer();
PrintWriter pw=new PrintWriter(System.out);
Scanner scn=new Scanner(System.in);
DecimalFormat deciFormat = new DecimalFormat();
deciFormat.setMaximumFractionDigits(9);
int T = scn.nextInt();
double si,de,ra,p,h,ans;
double li = 0.000001;
while(T-->0){
int n = scn.nextInt();
si = 0.5;
de = (n-1)*(90.0/(1.0*n));
ra = Math.toRadians(de);
p = si*Math.tan(ra);
h = si/Math.cos(ra);
//pw.println(p+" "+h);
if(n%2==0||p-h>li)
ans = 2.0*p;
else
ans = 2.0*h;
str.append(deciFormat.format(ans)+"\n");
}
pw.println(str.toString());
pw.close();
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 9114dbc9722ea983ac2229be2b2a02e4 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.util.*;
public class C implements Runnable {
boolean judge = false;
FastReader scn;
PrintWriter out;
String INPUT = "";
void solve() {
int t = scn.nextInt();
while (t-- > 0) {
int n = 2 * scn.nextInt();
if (n % 4 == 0) {
out.println(1 / Math.tan(Math.PI / n));
}
}
}
public void run() {
long time = System.currentTimeMillis();
boolean oj = System.getProperty("ONLINE_JUDGE") != null || judge;
out = new PrintWriter(System.out);
scn = new FastReader(oj);
solve();
out.flush();
if (!oj) {
System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
}
}
public static void main(String[] args) {
new Thread(null, new C(), "Main", 1 << 28).start();
}
class FastReader {
InputStream is;
public FastReader(boolean onlineJudge) {
is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
}
byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
int readByte() {
if (lenbuf == -1)
throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return -1;
}
return inbuf[ptrbuf++];
}
boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b))
;
return b;
}
double nextDouble() {
return Double.parseDouble(next());
}
char nextChar() {
return (char) skip();
}
String next() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
String nextLine() {
int b = skip();
StringBuilder sb = new StringBuilder();
while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
char[] next(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
int nextInt() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
long nextLong() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
char[][] nextMatrix(int n, int m) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++)
map[i] = next(m);
return map;
}
int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
int[][] next2DInt(int n, int m) {
int[][] arr = new int[n][];
for (int i = 0; i < n; i++) {
arr[i] = nextIntArray(m);
}
return arr;
}
long[][] next2DLong(int n, int m) {
long[][] arr = new long[n][];
for (int i = 0; i < n; i++) {
arr[i] = nextLongArray(m);
}
return arr;
}
int[] shuffle(int[] arr) {
Random r = new Random();
for (int i = 1, j; i < arr.length; i++) {
j = r.nextInt(i);
int c = arr[i];
arr[i] = arr[j];
arr[j] = c;
}
return arr;
}
long[] shuffle(long[] arr) {
Random r = new Random();
for (int i = 1, j; i < arr.length; i++) {
j = r.nextInt(i);
long c = arr[i];
arr[i] = arr[j];
arr[j] = c;
}
return arr;
}
int[] uniq(int[] arr) {
arr = scn.shuffle(arr);
Arrays.sort(arr);
int[] rv = new int[arr.length];
int pos = 0;
rv[pos++] = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] != arr[i - 1]) {
rv[pos++] = arr[i];
}
}
return Arrays.copyOf(rv, pos);
}
long[] uniq(long[] arr) {
arr = scn.shuffle(arr);
Arrays.sort(arr);
long[] rv = new long[arr.length];
int pos = 0;
rv[pos++] = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] != arr[i - 1]) {
rv[pos++] = arr[i];
}
}
return Arrays.copyOf(rv, pos);
}
int[] reverse(int[] arr) {
int l = 0, r = arr.length - 1;
while (l < r) {
arr[l] = arr[l] ^ arr[r];
arr[r] = arr[l] ^ arr[r];
arr[l] = arr[l] ^ arr[r];
l++;
r--;
}
return arr;
}
long[] reverse(long[] arr) {
int l = 0, r = arr.length - 1;
while (l < r) {
arr[l] = arr[l] ^ arr[r];
arr[r] = arr[l] ^ arr[r];
arr[l] = arr[l] ^ arr[r];
l++;
r--;
}
return arr;
}
int[] compress(int[] arr) {
int n = arr.length;
int[] rv = Arrays.copyOf(arr, n);
rv = uniq(rv);
for (int i = 0; i < n; i++) {
arr[i] = Arrays.binarySearch(rv, arr[i]);
}
return arr;
}
long[] compress(long[] arr) {
int n = arr.length;
long[] rv = Arrays.copyOf(arr, n);
rv = uniq(rv);
for (int i = 0; i < n; i++) {
arr[i] = Arrays.binarySearch(rv, arr[i]);
}
return arr;
}
void deepFillInt(Object array, int val) {
if (!array.getClass().isArray()) {
throw new IllegalArgumentException();
}
if (array instanceof int[]) {
int[] intArray = (int[]) array;
Arrays.fill(intArray, val);
} else {
Object[] objArray = (Object[]) array;
for (Object obj : objArray) {
deepFillInt(obj, val);
}
}
}
void deepFillLong(Object array, long val) {
if (!array.getClass().isArray()) {
throw new IllegalArgumentException();
}
if (array instanceof long[]) {
long[] intArray = (long[]) array;
Arrays.fill(intArray, val);
} else {
Object[] objArray = (Object[]) array;
for (Object obj : objArray) {
deepFillLong(obj, val);
}
}
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | cceb46ef2dd78de20202ecc6d14a2f9d | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class C1 {
private static double polyapothem(double n, double a) {
// Side and side length cannot be negative
if (a < 0 && n < 0)
return -1;
// Degree converted to radians
return (a / (2 * java.lang.Math.tan((180 / n)
* Math.PI / 180)));
}
public static void main(String[] args) throws Exception {
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
int test = Integer.parseInt(br.readLine());
while (test-- > 0) {
int n = Integer.parseInt(br.readLine());
double ans = polyapothem(2 * n, 1);
System.out.println(2 * ans);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | d39bbdedd779cf8f29f2599579fc1db5 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static long gcd(long a, long b){
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b) {
return (a*b)/gcd(a, b);
}
public static void sortbyColumn(int arr[][], int col)
{
Arrays.sort(arr, new Comparator<int[]>() {
@Override
public int compare(final int[] entry1,
final int[] entry2) {
if (entry1[col] > entry2[col])
return 1;
else
return -1;
}
});
}
static long func(long a[],long size,int s){
long max1=a[s];
long maxc=a[s];
for(int i=s+1;i<size;i++){
maxc=Math.max(a[i],maxc+a[i]);
max1=Math.max(maxc,max1);
}
return max1;
}
public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
public U x;
public V y;
public Pair(U x, V y) {
this.x = x;
this.y = y;
}
public int hashCode() {
return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
}
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Pair<U, V> p = (Pair<U, V>) o;
return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
}
public int compareTo(Pair<U, V> b) {
int cmpU = x.compareTo(b.x);
return cmpU != 0 ? cmpU : y.compareTo(b.y);
}
public String toString() {
return String.format("(%s, %s)", x.toString(), y.toString());
}
}
//static LinkedList<Integer> li[]=new LinkedList[100001];
static int ans1=0,ans2=0;
static int dist[];
static int visited[];
//static int arr[];
static ArrayList<Integer> adj[];
public static void main(String args[]){
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter w = new PrintWriter(outputStream);
int t,i,j;
t=in.nextInt();
while(t-->0){
int n=in.nextInt();
int sides=2*n;
double angle=(double)2*Math.PI/(double)sides;
//w.println(angle);
double sum=0;
i=1;
double nt=Math.PI/2;
int tot=sides-4;
tot=tot/4;
for(i=0;i<tot;i++){
//w.println(Math.sin(angle));
sum+=Math.sin(angle*(i+1));
//i++;
}
sum*=2;
sum++;
w.println(sum);
}
w.close();
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 40a3707a928db6635b0f500532913141 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;
public class D {
public void run() throws Exception {
FastScanner sc = new FastScanner();
int test = sc.nextInt();
outer:
for (int q = 0; q<test; q++) {
double n = sc.nextDouble();
if (n == 2) System.out.println(1);
else {
if (n%4 == 0) {
double side = 1;
double left = n-4;
double angle = Math.PI*(2*n-2)/2/n;
double val = Math.PI-angle;
for (int i = 0; i<=left/2; i++) {
side+=Math.sin(val);
double sum = Math.PI*2-(angle+Math.PI-val);
val = sum;
}
System.out.println(side*2-1);
}
else {
double side = 1;
double left = n-4;
double angle = Math.PI*(2*n-2)/2/n;
double val = Math.PI-angle;
for (int i = 0; i<=left/2; i++) {
side+=Math.sin(val);
double sum = Math.PI*2-(angle+Math.PI-val);
val = sum;
}
System.out.println(side*2-1);
}
}
}
}
static class FastScanner {
public BufferedReader reader;
public StringTokenizer tokenizer;
public FastScanner() {
reader = new BufferedReader(new InputStreamReader(System.in), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public static void main (String[] args) throws Exception {
new D().run();
}
public void shuffleArray(long[] arr) {
int n = arr.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
long tmp = arr[i];
int randomPos = i + rnd.nextInt(n-i);
arr[i] = arr[randomPos];
arr[randomPos] = tmp;
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 3a69207ba83bfbb7e793cc95d07d8692 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | // Working program using Reader Class
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.*;
public class Code
{
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main(String[] args) throws IOException
{
Scanner sc=new Scanner(System.in);
//Reader sc=new Reader();
StringBuilder print=new StringBuilder();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt()*2;
print.append(Math.cos(Math.PI/n)/Math.sin(Math.PI/n)).append("\n");
}
System.out.print(print);
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | bf7b35bc2fc007c60af235ee3e9b7906 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes |
import java.math.*;
import java.util.*;
public class asol {
public static double tan(double sides) {
double k = 180.0/sides;
double a = Math.toRadians(k);
return Math.tan(a);
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int tc = scan.nextInt();
while(tc--!=0) {
int n = scan.nextInt();
System.out.printf("%.6f",(1.0/tan(2*n)));
System.out.println();
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | a938f6d42dddbafddfd3f0769c69b708 | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.util.*;
public class E87C1
{
static PrintWriter out=new PrintWriter((System.out));
public static void main(String args[])throws IOException
{
Reader sc=new Reader();
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
solve(n);
}
out.close();
}
public static void solve(int n)
{
double ans=1/(Math.tan(Math.PI/(2*n)));
out.println(ans);
}
static class Reader
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next()
{
while(!st.hasMoreTokens())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(Exception e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt()
{
return Integer.parseInt(next());
}
public long nextLong()
{
return Long.parseLong(next());
}
public double nextDouble()
{
return Double.parseDouble(next());
}
public String nextLine()
{
try
{
return br.readLine();
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
public boolean hasNext()
{
String next=null;
try
{
next=br.readLine();
}
catch(Exception e)
{
}
if(next==null)
{
return false;
}
st=new StringTokenizer(next);
return true;
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | f0c313c1aede5e254e8199683f83a3fe | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
MyScanner in = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int T=in.nextInt();
for(int test=0;test<T;test++){
int n = in.nextInt();
int k = 2*n;
double a = ((double) (k*180-360))/(2*k);
a = a * Math.PI / 180;
double diag = 1/Math.cos(a);
double ans = Math.sqrt(diag*diag-1);
out.println(ans);
}
out.close();
}
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 48df7a630042541dba6696716838c5ae | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Pranay2516
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC1 solver = new TaskC1();
int testCount = Integer.parseInt(in.next());
for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}
static class TaskC1 {
public void solve(int testNumber, FastReader in, PrintWriter out) {
double n = in.nextInt();
double angle = (2 * n - 2) * 90.0 / n;
out.println(Math.round(Math.tan(Math.toRadians(angle / 2)) * 1000000000.0) / 1000000000.0);
}
}
static class FastReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private FastReader.SpaceCharFilter filter;
public FastReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output | |
PASSED | 05e426368db97ea1e9687ce3b63ddfae | train_001.jsonl | 1589707200 | The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square. | 256 megabytes | import java.io.*;
import java.util.*;
public class edr87C1 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(br.readLine());
while(t-- > 0)
{
double n = Double.parseDouble(br.readLine());
double k = 90/n;
k = Math.toRadians(k);
double ans = Math.tan(k);
System.out.println(1/ans);
}
}
}
| Java | ["3\n2\n4\n200"] | 2 seconds | ["1.000000000\n2.414213562\n127.321336469"] | null | Java 8 | standard input | [
"binary search",
"geometry",
"ternary search",
"math"
] | 0c7a476716445c535a61f4e81edc7f75 | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single even integer $$$n$$$ ($$$2 \le n \le 200$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon. | 1,400 | Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.