Общий форумhow to know when there are no more inputs #include<stdio.h> #include<math.h> int main(){ unsigned long long int a,b,c,d; double Sqrt,Sqrt1,Sqrt2,Sqrt3; scanf("%llu %llu %llu %llu",&a,&b,&c,&d); Sqrt=sqrt(a); Sqrt1=sqrt(b); Sqrt2=sqrt(c); Sqrt3=sqrt(d); printf(" %0.4lf %0.4lf %0.4lf %0.4lf",Sqrt,Sqrt1,Sqrt2,Sqrt3); } Edited by author 23.06.2022 13:46 Edited by author 23.06.2022 13:46 there is nowhere mentioned only 4 inputs are there so while(cin>>x) would be the conditional i hope it helps A bug fixed in the checker program that allowed passing arbitrary expressions as a first argument to the substring function. According to the problem statements only variables are allowed to be passed there. Accepted solutions have been rejudged. 26 authors lost the Solved status for the problem. a , b , c = list(map(int , input().split())) A , B , C = list(map(int , input().split())) if a+c >= A: if a >= A: c =c a-=A else: c=A-a a-=A-c if b+c >= B: if b >= B: c =c b-=B else: c=B-b a-=A-c if a + b + c >= C: print('It is a kind of magic') else: print('There are no miracles in life') else: print('There are no miracles in life') else: print('There are no miracles in life') Thanks i rewirte in java 1.8 that helps me a lot, thank you so much The missing condition added to the English version of the statement: The cell in which the minus remains should not change. The Russian version of the statement was correct. import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { String a = "Emperor Penguin"; String b = "Macaroni Penguin"; String c = "Little Penguin"; int countA = 0; int countB = 0; int countC = 0; Scanner sc = new Scanner(System.in); int n = sc.nextInt(); List<String> list = new ArrayList<>(n); sc.nextLine(); for (int i = 0; i < n; i++){ list.add(sc.nextLine()); } for (String item: list){ if (item.equals(a)){ countA++; } else if (item.equals(b)) { countB++; } else if (item.equals(c)) { countC++; } } int max = Math.max(Math.max(countA,countB),countC); if (max == countA){ System.out.println(a); } else if (max == countB) { System.out.println(b); } else if (max == countC) { System.out.println(c); } } } Edited by author 18.11.2017 03:29 Thanks to AI. After 15 years since the first submission, I finally know how to solve this problem. If you got WA #28 - check int64 overflow The limitation on N was changed to reflect the actual test data. Instead of the old N < 10^600 the limitation was set to 0 < N < 10^300. Note that this is not the limitation on the input, but rather on the output. The number given to the input has about twice as many digits, previously up to ~1200 digits, now up to ~600 digits, but the actual test data was always only up to ~600 digits. Edge case N=0 was also missing in the test data, and is now explicitly disallowed by the limitation. New thorough tests were added within the new limitations. The time limit was reduced from 2.0 sec to 1.0 sec. All solutions have been rejudged. 192 authors lost, and 12 other authors gained the Solved status for the problem. Bugs fixed in the checker program. 1. The total length of dangerous segments was not always correctly verified against the canonical answer. Most prominently, the following output was previously accepted for the sample input (test 1), which has the total dangerous length 1.0 with the optimal one being 0.8: 2 1.0 1.5 0.0 1.5 2. Precision issues were fixed that were causing solutions with certain output rounding strategies being rejected (most commonly, WA8). The limitation on the number of pieces of furniture N was updated in the problem statements from N >= 0 to N >= 1 to reflect the actual test data. Additionally, the time limit was reduced from 2.0 sec to 1.0 sec. All solutions have been rejudged. 21 authors lost, and 2 other authors gained the Solved status for the problem. import java.io.IOException; import java.util.Scanner; public class Main { public static int rent = 100; public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(System.in); int numberOfFriends = Integer.parseInt(scanner.nextLine()); int totalGuests = 2; for (int i = 0; i < numberOfFriends; i++) { String answer = scanner.nextLine(); if (answer.contains("+")){ totalGuests += 2; }else{ totalGuests++; } } if (totalGuests == 13){ totalGuests++; } int total = totalGuests*rent; System.out.println(total);
scanner.close(); } } #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int k , n; cin >> k >> n; int sum = 0; while(n--) { int a; cin >> a; sum += a; sum -= min(sum , k); } cout << sum; } the solution is n-th fibonaci number write every option for evidence #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; //the answer is F[n] - fibonnaci number //76 > 3 vector <long long> dp(n + 2); dp[1] = 2; dp[2] = 2; for(int i = 3; i <= n; i++)dp[i] = dp[i - 1] + dp[i - 2]; cout << dp[n]; } All the trouble are caused by precision. The first submittion includes the code: angle_ACB = math.acos((x1*x2+y1*y2+z1*z2) / (len_CA*len_CB)) Then I got RE#8 in python, WA#8 in C++. Next I change the code to: angle_ACB = math.acos(0.5*(CA_sqr + CB_sqr - len_AB**2) / (len_CA*len_CB)) in python angle_ACB = acos(0.5* (CA_sqr + CB_sqr - sqr(len_AB))/(len_CA*len_CB)) in C++ Then I got RE#48 in python, WA#48 in C++. So I am sure the trouble is caused by the precision because of the function sqrt()! Sometimes, the cos(angle_ACB) is smaller than -1. Then the problem occurred by using acos(x) if x<-1. You need to handle this situation. Pls, anyone give me some hint about test #2 ! Thanks Consider this test case: 4 5 10 0000 0000 0000 0000 it helped me with WA2 be carefull you cann't create a dsu of size 10^9 given becasue max array size limit is roughly 10^7. hint: you do not need to track all the node parents instead need to track parents of those which only appears in the question. here is my soulution(c++): #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // priority_queue<type, std::vector<type>, decltype(cmp)> pq(cmp); // set/multiset<type, decltype(cmp)> s(cmp); // map<key_type, val_type, decltype(cmp)> m(cmp); // sort(v.begin(), v.end(), cmp) // cmp = custom_lamda_compare_function|syntax: [capture](parameters) -> return_type {} // typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag, // tree_order_statistics_node_update> indexed_set;
using namespace std; using namespace __gnu_pbds; using namespace std; class DSU{ private: map<int,pair<int, int>> parent; public: DSU(int size){} pair<int, int> find(int node){ if(parent.find(node) == parent.end()){ return {node, -1}; } return parent[node]; } bool union_set(int node1, int node2, int p){ auto it = find(node2); int root = it.first; int rootP = it.second; if(rootP == -1){ parent[node2] = {node1, p}; return true; } else if(root < node1){ parent[node2] = {node1, p}; return union_set(root, node1 - 1, rootP ^ p); } else if(root > node1){ return union_set(node1, root - 1, rootP ^ p); } else{ if(rootP == p) return true; else return false; } } }; int main(){ ////////////////////////////////////////////////////// ios_base::sync_with_stdio(false); cin.tie(NULL); ////////////////////////////////////////////////////// int t; // cin>>t; // int ct = 0; t = 1; while(t--){ while(true){ int n; cin>>n; if(n == -1){ break; } DSU dsu(n); int q; cin>>q; int ans = 0; bool b = false; while(q--){ int x, y, p; string str; cin>>x>>y>>str; p = (str == "even") ? 0 : 1; bool is = dsu.union_set(x, y, p); if(is && !b){ ans++; } else{ b = true; } } cout<<ans<<'\n'; } } } I did Dijkstra algorithm for S to F, but seems to exceeds time on test #3 ? Anyone got a clue? Tnx in advance Well, I do not know what this test is, but the answer for this test is "No solution". I don't know how to solve this problem with Dijkstra algorithm. My approach is another. Perhaps one pair of tests below can help you to understand the problem more clearely: 7 7 1 2 10 2 3 10 3 4 5 1 5 1 5 6 50 6 7 50 7 3 50 1 4 ans: 156 7 7 1 2 10 2 3 10 3 4 5 1 5 50 5 6 50 6 7 50 7 3 50 1 4 ans: 205 What you need to do is to find the path with maximum weights of all edges while Dijkstra tries to find minimum. You're solving the wrong problem. I was getting TLE 16 with inversed SPFA (longest path) when using DFS. Switched to BFS (queue instead of recursion) and got AC. It can be done with only 3 cables with max value of 1. Got AC “You are to help Andrew to find the way to connect hubs so that all above conditions are satisfied.” So you can output any correct answer. I got an AC too, with a program outputting only 3 connections for the sample case. The only thing that actually matters is the very first value of the output - the maximum length of a cable. Generally it means the problem is much simpler than finding the optimal MST. What is the test 4? idk i just love chiken wings so much Edited by author 19.11.2025 14:03 In Go you should use `fmt.Scanf("%d %d\n", &a, &b)` instead of `fmt.Scanf("%d %d", &a, &b)`! Using the latter results in reading zeroes. |
|