Common BoardHi I am new to forum. I just tried Reverse Root problem and had judgement result as "wrong answer". Below is my code .. just wondering what is wrong with it. Because I ran it on Visual Studio and it seems to give right numbers. Many Thanks ----------------------------------------- #include <iostream> #include <iomanip> #include <cmath> int main(){ double arr[65536]; int i = 0; int value = 0; while(std::cin >> value){ arr[i++] = sqrt(static_cast<double> (value)); } std::cout<<std::setprecision(4)<<std::fixed; while(i--) std::cout << arr[i] << std::endl; } #include <iostream> #include <cmath> using namespace std; int max (int a,int b) { return a>b? a:b;} int min (int a,int b) { return a>b? b:a;} double const pi=acos(-1.0); int main() { int a,b,d; int r1,r2,R1,R2,h; cin>>a>>b>>d>>r1>>R1>>r2>>R2>>h; if (2*max(R1,R2)<=min(a,b) && pi*R1*R1+pi*R2*R2<=a*b) { cout<<"YES"; return 0; } cout<<"NO"; return 0; } Edited by author 03.07.2011 21:46 Don't forget about case when h > d (so trays are touching plate a little bit lower) and try to place trays in opposite corners of plate. A good way to get a competitive edge is to write down a game plan for what you're going to do in a contest round. This will help you script out your actions, in terms of what to do both when things go right and when things go wrong. This way you can spend your thinking time in the round figuring out programming problems and not trying to figure out what the heck you should do next... it's sort of like precomputing your reactions to most situations. Mental preparation is also important. Game Plan For A Contest Round Read through ALL the problems FIRST; sketch notes with algorithm, complexity, the numbers, data structs, tricky details, ... * Brainstorm many possible algorithms - then pick the stupidest that works! * DO THE MATH! (space & time complexity, and plug in actual expected and worst case numbers) * Try to break the algorithm - use special (degenerate?) test cases * Order the problems: shortest job first, in terms of your effort (shortest to longest: done it before, easy, unfamiliar, hard) Coding a problem - For each, one at a time: * Finalize algorithm * Create test data for tricky cases * Write data structures * Code the input routine and test it (write extra output routines to show data?) * Code the output routine and test it * Stepwise refinement: write comments outlining the program logic * Fill in code and debug one section at a time * Get it working & verify correctness (use trivial test cases) * Try to break the code - use special cases for code correctness * Optimize progressively - only as much as needed, and keep all versions (use hard test cases to figure out actual runtime) Time management strategy and "damage control" scenarios Have a plan for what to do when various (foreseeable!) things go wrong; imagine problems you might have and figure out how you want to react. The central question is: "When do you spend more time debugging a program, and when do you cut your losses and move on?". Consider these issues: * How long have you spent debugging it already? * What type of bug do you seem to have? * Is your algorithm wrong? * Do you data structures need to be changed? * Do you have any clue about what's going wrong? * A short amount (20 mins) of debugging is better than switching to anything else; but you might be able to solve another from scratch in 45 mins. * When do you go back to a problem you've abandoned previously? * When do you spend more time optimizing a program, and when do you switch? * Consider from here out - forget prior effort, focus on the future: how can you get the most points in the next hour with what you have? Have a checklist to use before turning in your solutions: * Code freeze five minutes before end of contest? Turn asserts off. * Turn off debugging output. Tips & Tricks * Brute force it when you can * KISS: Simple is smart! * Hint: focus on limits (specified in problem statement) * Waste memory when it makes your life easier (if you can get away with it) * Don't delete your extra debugging output, comment it out * Optimize progressively, and only as much as needed * Keep all working versions! * Code to debug: o whitespace is good, o use meaningful variable names, o don't reuse variables, o stepwise refinement, o COMMENT BEFORE CODE. * Avoid pointers if you can * Avoid dynamic memory like the plague: statically allocate everything. * Try not to use floating point; if you have to, put tolerances in everywhere (never test equality) * Comments on comments: o Not long prose, just brief notes o Explain high-level functionality: ++i; /* increase the value of i by */ is worse than useless o Explain code trickery o Delimit & document functional sections o As if to someone intelligent who knows the problem, but not the code o Anything you had to think about o Anything you looked at even once saying, "now what does that do again?" o Always comment order of array indices * Keep a log of your performance in each contest: successes, mistakes, and what you could have done better; use this to rewrite and improve your game plan! Complexity Basics and order notation The fundamental basis of complexity analysis revolves around the notion of ``big oh'' notation, for instance: O(N). This means that the algorithm's execution speed or memory usage will double when the problem size doubles. An algorithm of O(N 2) will run about four times slower (or use 4x more space) when the problem size doubles. Constant-time or space algorithms are denoted O(1). This concept applies to time and space both; here we will concentrate discussion on time. One deduces the O() run time of a program by examining its loops. The most nested (and hence slowest) loop dominates the run time and is the only one mentioned when discussing O() notation. A program with a single loop and a nested loop (presumably loops that execute N times each) is O(N 2), even though there is also a O(N) loop present. Of course, recursion also counts as a loop and recursive programs can have orders like O(b N), O(N!), or even O(N N). Rules of thumb * When analyzing an algorithm to figure out how long it might run for a given dataset, the first rule of thumb is: modern (2004) computers can deal with 100M actions per second. In a five second time limit program, about 500M actions can be handled. Really well optimized programs might be able to double or even quadruple that number. Challenging algorithms might only be able to handle half that much. Current contests usually have a time limit of 1 second for large datasets. * 16MB maximum memory use * 210 ~approx~ 10 3 * If you have k nested loops running about N iterations each, the program has O(N k) complexity. * If your program is recursive with b recursive calls per level and has l levels, the program O(b l) complexity. * Bear in mind that there are N! permutations and 2 n subsets or combinations of N elements when dealing with those kinds of algorithms. * The best times for sorting N elements are O(N log N). * DO THE MATH! Plug in the numbers. Examples A single loop with N iterations is O(N): 1 sum = 0 2 for i = 1 to n 3 sum = sum + i A double nested loop is often O(N 2): # fill array a with N elements 1 for i = 1 to n-1 2 for j = i + 1 to n 3 if (a[i] > a[j]) swap (a[i], a[j]) Note that even though this loop executes N x (N+1) / 2 iterations of the if statement, it is O(N 2) since doubling N quadruples the execution times. Consider this well balanced binary tree with four levels: An algorithm that traverses a general binary tree will have complexity O(2 N). Solution Paradigms Generating vs. Filtering Programs that generate lots of possible answers and then choose the ones that are correct (imagine an 8-queen solver) are filters. Those that hone in exactly on the correct answer without any false starts are generators. Generally, filters are easier (faster) to code and run slower. Do the math to see if a filter is good enough or if you need to try and create a generator. Precomputation Sometimes it is helpful to generate tables or other data structures that enable the fastest possible lookup of a result. This is called precomputation (in which one trades space for time). One might either compile precomputed data into a program, calculate it when the program starts, or just remember results as you compute them. A program that must translate letters from upper to lower case when they are in upper case can do a very fast table lookup that requires no conditionals, for example. Contest problems often use prime numbers - many times it is practical to generate a long list of primes for use elsewhere in a program. Decomposition (The Hardest Thing At Programming Contests) While there are fewer than 20 basic algorithms used in contest problems, the challenge of combination problems that require a combination of two algorithms for solution is daunting. Try to separate the cues from different parts of the problem so that you can combine one algorithm with a loop or with another algorithm to solve different parts of the problem independently. Note that sometimes you can use the same algorithm twice on different (independent!) parts of your data to significantly improve your running time. Symmetries Many problems have symmetries (e.g., distance between a pair of points is often the same either way you traverse the points). Symmetries can be 2-way, 4-way, 8-way, and more. Try to exploit symmetries to reduce execution time. For instance, with 4-way symmetry, you solve only one fourth of the problem and then write down the four solutions that share symmetry with the single answer (look out for self-symmetric solutions which should only be output once or twice, of course). Forward vs. Backward Surprisingly, many contest problems work far better when solved backwards than when using a frontal attack. Be on the lookout for processing data in reverse order or building an attack that looks at the data in some order or fashion other than the obvious. Simplification Some problems can be rephrased into a somewhat different problem such that if you solve the new problem, you either already have or can easily find the solution to the original one; of course, you should solve the easier of the two only. Alternatively, like induction, for some problems one can make a small change to the solution of a slightly smaller problem to find the full answer. The Idea Solving a problem using complete search is based on the ``Keep It Simple, Stupid'' principle. The goal of solving contest problems is to write programs that work in the time allowed, whether or not there is a faster algorithm. Complete search exploits the brute force, straight-forward, try-them-all method of finding the answer. This method should almost always be the first algorithm/solution you consider. If this works within time and space constraints, then do it: it's easy to code and usually easy to debug. This means you'll have more time to work on all the hard problems, where brute force doesn't work quickly enough. In the case of a problem with only fewer than a couple million possibilities, iterate through each one of them, and see if the answer works. Careful, Careful Sometimes, it's not obvious that you use this methodology. Problem: Party Lamps [IOI 98] You are given N lamps and four switches. The first switch toggles all lamps, the second the even lamps, the third the odd lamps, and last switch toggles lamps 1, 4, 7, 10, ... . Given the number of lamps, N, the number of button presses made (up to 10,000), and the state of some of the lamps (e.g., lamp 7 is off), output all the possible states the lamps could be in. Naively, for each button press, you have to try 4 possibilities, for a total of 410000 (about 106020 ), which means there's no way you could do complete search (this particular algorithm would exploit recursion). Noticing that the order of the button presses does not matter gets this number down to about 100004 (about 1016 ), still too big to completely search (but certainly closer by a factor of over 106000 ). However, pressing a button twice is the same as pressing the button no times, so all you really have to check is pressing each button either 0 or 1 times. That's only 24 = 16 possibilities, surely a number of iterations solvable within the time limit. Problem 3: The Clocks [IOI 94] A group of nine clocks inhabits a 3 x 3 grid; each is set to 12:00, 3:00, 6:00, or 9:00. Your goal is to manipulate them all to read 12:00. Unfortunately, the only way you can manipulate the clocks is by one of nine different types of move, each one of which rotates a certain subset of the clocks 90 degrees clockwise. Find the shortest sequence of moves which returns all the clocks to 12:00. The ``obvious'' thing to do is a recursive solution, which checks to see if there is a solution of 1 move, 2 moves, etc. until it finds a solution. This would take 9k time, where k is the number of moves. Since k might be fairly large, this is not going to run with reasonable time constraints. Note that the order of the moves does not matter. This reduces the time down to k9 , which isn't enough of an improvement. However, since doing each move 4 times is the same as doing it no times, you know that no move will be done more than 3 times. Thus, there are only 49 possibilities, which is only 262,072, which, given the rule of thumb for run-time of more than 10,000,000 operations in a second, should work in time. The brute-force solution, given this insight, is perfectly adequate. Sample Problems Milking Cows [USACO 1996 Competition Round] Given a cow milking schedule (Farmer A milks from time 300 to time 1000, Farmer B from 700 to 1200, etc.), calculate * The longest time interval in which at least one cow was being milked * The longest time interval in which no cow is being milked Perfect Cows & Perfect Cow Cousins [USACO 1995 Final Round] A perfect number is one in which the sum of the proper divisors add up to the number. For example, 28 = 1 + 2 + 4 + 7 + 14. A perfect pair is a pair of numbers such that the sum of the proper divisor of each one adds up to the other. There are, of course, longer perfect sets, such that the sum of the divisors of the first add up to the second, the second's divisors to the third, etc., until the sum of the last's proper divisors add up to the first number. Each cow in Farmer John's ranch is assigned a serial number. from 1 to 32000. A perfect cow is one which has a perfect number as its serial. A group of cows is a set of perfect cow cousins if their serial numbers form a perfect set. Find all perfect cows and perfect cow cousins. Sample Problem: Barn Repair [1999 USACO Spring Open] There is a long list of stalls, some of which need to be covered with boards. You can use up to N (1 <= N <= 50) boards, each of which may cover any number of consecutive stalls. Cover all the necessary stalls, while covering as few total stalls as possible. The Idea The basic idea behind greedy algorithms is to build large solutions up from smaller ones. Unlike other approaches, however, greedy algorithms keep only the best solution they find as they go along. Thus, for the sample problem, to build the answer for N = 5, they find the best solution for N = 4, and then alter it to get a solution for N = 5. No other solution for N = 4 is ever considered. Greedy algorithms are fast, generally linear to quadratic and require little extra memory. Unfortunately, they usually aren't correct. But when they do work, they are often easy to implement and fast enough to execute. Problems There are two basic problems to greedy algorithms. How to Build How does one create larger solutions from smaller ones? In general, this is a function of the problem. For the sample problem, the most obvious way to go from four boards to five boards is to pick a board and remove a section, thus creating two boards from one. You should choose to remove the largest section from any board which covers only stalls which don't need covering (so as to minimize the total number of stalls covered). To remove a section of covered stalls, take the board which spans those stalls, and make into two boards: one of which covers the stalls before the section, one of which covers the stalls after the section. Does it work? The real challenge for the programmer lies in the fact that greedy solutions don't always work. Even if they seem to work for the sample input, random input, and all the cases you can think of, if there's a case where it won't work, at least one (if not more!) of the judges' test cases will be of that form. For the sample problem, to see that the greedy algorithm described above works, consider the following: Assume that the answer doesn't contain the large gap which the algorithm removed, but does contain a gap which is smaller. By combining the two boards at the end of the smaller gap and splitting the board across the larger gap, an answer is obtained which uses as many boards as the original solution but which covers fewer stalls. This new answer is better, so therefore the assumption is wrong and we should always choose to remove the largest gap. If the answer doesn't contain this particular gap but does contain another gap which is just as large, doing the same transformation yields an answer which uses as many boards and covers as many stalls as the other answer. This new answer is just as good as the original solution but no better, so we may choose either. Thus, there exists an optimal answer which contains the large gap, so at each step, there is always an optimal answer which is a superset of the current state. Thus, the final answer is optimal. Conclusions If a greedy solution exists, use it. They are easy to code, easy to debug, run quickly, and use little memory, basically defining a good algorithm in contest terms. The only missing element from that list is correctness. If the greedy algorithm finds the correct answer, go for it, but don't get suckered into thinking the greedy solution will work for all problems. Sample Problems Sorting a three-valued sequence [IOI 1996] You are given a three-valued (1, 2, or 3) sequence of length up to 1000. Find a minimum set of exchanges to put the sequence in sorted order. Algorithm The sequence has three parts: the part which will be 1 when in sorted order, 2 when in sorted order, and 3 when in sorted order. The greedy algorithm swaps as many as possible of the 1's in the 2 part with 2's in the 1 part, as many as possible 1's in the 3 part with 3's in the 1 part, and 2's in the 3 part with 3's in the 2 part. Once none of these types remains, the remaining elements out of place need to be rotated one way or the other in sets of 3. You can optimally sort these by swapping all the 1's into place and then all the 2's into place. Analysis: Obviously, a swap can put at most two elements in place, so all the swaps of the first type are optimal. Also, it is clear that they use different types of elements, so there is no ``interference'' between those types. This means the order does not matter. Once those swaps have been performed, the best you can do is two swaps for every three elements not in the correct location, which is what the second part will achieve (for example, all the 1's are put in place but no others; then all that remains are 2's in the 3's place and vice-versa, and which can be swapped). Friendly Coins - A Counterexample [abridged] Given the denominations of coins for a newly founded country, the Dairy Republic, and some monetary amount, find the smallest set of coins that sums to that amount. The Dairy Republic is guaranteed to have a 1 cent coin. Algorithm: Take the largest coin value that isn't more than the goal and iterate on the total minus this value. (Faulty) Analysis: Obviously, you'd never want to take a smaller coin value, as that would mean you'd have to take more coins to make up the difference, so this algorithm works. Maybe not: Okay, the algorithm usually works. In fact, for the U.S. coin system {1, 5, 10, 25}, it always yields the optimal set. However, for other sets, like {1, 5, 8, 10} and a goal of 13, this greedy algorithm would take one 10, and then three 1's, for a total of four coins, when the two coin solution {5, 8} also exists. Topological Sort Given a collection of objects, along with some ordering constraints, such as "A must be before B," find an order of the objects such that all the ordering constraints hold. Algorithm: Create a directed graph over the objects, where there is an arc from A to B if "A must be before B." Make a pass through the objects in arbitrary order. Each time you find an object with in-degree of 0, greedily place it on the end of the current ordering, delete all of its out-arcs, and recurse on its (former) children, performing the same check. If this algorithm gets through all the objects without putting every object in the ordering, there is no ordering which satisfies the constraints. # include <stdio.h> # include <conio.h> # include <math.h> # include <stdlib.h> # include <time.h> # include <limits.h> int count = 0; int A[100][100] , M , N , gidildi[100] = {0}; grafoku() { int i , j , k; scanf("%i %i",&N,&M); for( i = 0 ; i < N ; ++i ) for( k = 0 ; k < N ; ++k ) A[i][k] = 0;
for( k = 0 ; k < M ; ++k ){ scanf("%d %d",&i , &j); A[i - 1][j - 1] = 1; A[j - 1][i - 1] = 1; }
return 0; } DFS( unsigned int dugum ) { int gidildi[100] = {0}; unsigned i;
gidildi[dugum] = 1; for( i = 0 ; i < N ; ++i ) if( A[dugum][i] != 0 && gidildi[i] == 0 ) DFS(i); } int kontrol(int dugum , int i) { A[dugum][i] = 0; A[i][dugum] = 0; DFS(i); for( i = 0 ; i < N ; ++i ) gidildi[i] = 0; if( count == N ){ count = 0; return 1; } count = 0; return 0; } main() { int i , j = 1 , toplam = 0 , tek = 0 , euler_yolu[100] = {0} , dugum , sinir;
grafoku();
/*Euler yolu var mı?*/
for( i = 0 ; i < N ; ++i ){ for( j = 0 ; j < N ; ++j ) toplam += A[i][j]; if( toplam % 2 == 1 ) tek++; toplam = 0; }
if( !( tek == 2 || tek == 0 ) ) return;
/*Euler yolu var mı?(bitti)*/
dugum = 0; for( i = 0 ; i < N ; ++i ) if( A[dugum][i] == 1 ) if( kontrol(dugum , i) ){ euler_yolu[j] = i; dugum = i; j++; i = 0; } else{ A[dugum][i] = 1; A[i][dugum] = 1; } /*yazdırılıyor.*/
for( i = 0 ; i <= M ; ++i ) printf("%i ",euler_yolu[i]);
system("pause"); }
Utkirova Mohinur Utkir qizi 1153 [1] 26 Aug 2012 15:20 Я ришила это задача 10^600 таким очен болшой число моя программа не работает Помагите мне Vi svoy kod napeshite, u menya toje nepoluchayetsa vmeste obsudim :) :)!! Is it possible to provide the test case? I think the test case is not 30 30 as said in a place in the forum because my code passes that test case I think. I got AC with a bruteforce (Depth First Search) algorithm in 0.218 sec. If you get TLE at test 39, it is something like this: N = 100 The element of A is all 0, except for a(99, 100) = a(100, 99) = 1. Don't forget that the way to store tree in simple array when (2i)th and (2i+1)th elements are childrens of (i)th element isn't working here because in worst case it costs about 2^n memory to store this array. Edited by author 27.08.2012 19:28 Hi admin, I misunderstood the problem. More precisely, I replaced the sentence: the problem set of any contest must contain at least x and at most y problems with this one: the problem set of any contest must contain either x or y problems It turned out that the modified version of the problem is also solvable, and I have designed the program for submittion. Unsurprisingly, I got Wrong Answer. Now, I will try to solve the original problem. And, admin, would you please consider to add the modified version to the ProblemSet? I use dp code. /////////////////// import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.StreamTokenizer; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; public class Timus_1651 { static StreamTokenizer st; public static void main(String[] args) throws IOException{ st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int n = nextInt(); int []a = new int [n+1]; for (int i = 1; i <=n; i++) { a[i] = nextInt(); } int []dp = new int [100001]; int []p = new int [100001]; int INF = (int)1e8; Arrays.fill(dp, INF); dp[a[1]] = 0; for (int i = 2; i <=n; i++) { if (dp[a[i]] > dp[a[i-1]]+1){ dp[a[i]] = dp[a[i-1]]+1; p[a[i]] = a[i-1]; } } int cur = a[n]; ArrayList<Integer> ans = new ArrayList<Integer>(); while (true){ ans.add(cur); if (cur == a[1]) break; cur = p[cur]; } Collections.reverse(ans); for (int i = 0; i < ans.size(); i++) { out.write(ans.get(i)+" "); } out.close(); } private static int nextInt() throws IOException{ st.nextToken(); return (int) st.nval; } } time 0.375 I use segmet tree Sorry for double-posting... Edited by author 25.08.2012 23:33 Второй абзац: > Профессор A - завсегдатай симпозиума решил следует заменить на > Профессор A, завсегдатай симпозиума, решил Четвёртый абзац: > в отличии > ведь в отличии от космологов, хронологи считают Правильно: > в отличие > ведь в отличие от космологов хронологи считают (Здесь по правилам запятую рекомендуется не ставить, однако она возможна.) Четвёртый абзац: > Сейчас он просто не мог ждать ни секунды (...), поэтому он сел в свой хрономобиль и отправился на встречу. Лучше убрать второе слово "он". Пятый абзац: > Так уже сейчас Следует добавить запятую: > Так, уже сейчас В исходных данных: > Далее следуют N строк, описывающие перекрёстки. Правильно: > Далее следуют N строк, описывающих перекрёстки. В исходных данных: > Любой список, содержит Запятая лишняя. В исходных данных: > В последней строке находится два числа. заменить на > В последней строке находятся два числа. В последнем предложении исходных данных точку с запятой лучше заменить просто на запятую. И ещё: в некоторых написаниях слов с буквой 'ё' эта буква присутствует, в некоторых - нет. Нехорошо. The correct answer for test 3 4 is 36. May be it will help someone I'm using gcc version 4.6.2 on SUSE linux Code compiles on my computer without error, but at server there are a lot of errors during compilation. This is compiling process errors: ________________________________________________________________________________________ 27e5fc42-d41b-42da-9ed8-452e7ff6161d 27e5fc42-d41b-42da-9ed8-452e7ff6161d(29) : error C2143: syntax error : missing ';' before 'type' 27e5fc42-d41b-42da-9ed8-452e7ff6161d(31) : error C2065: 'nail' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(31) : error C2109: subscript requires array or pointer type 27e5fc42-d41b-42da-9ed8-452e7ff6161d(31) : error C2065: 'nail' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(31) : error C2109: subscript requires array or pointer type 27e5fc42-d41b-42da-9ed8-452e7ff6161d(33) : error C2143: syntax error : missing ';' before 'type' 27e5fc42-d41b-42da-9ed8-452e7ff6161d(35) : error C2065: 'rope_lenght' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(35) : warning C4244: '+=' : conversion from 'double' to 'int', possible loss of data 27e5fc42-d41b-42da-9ed8-452e7ff6161d(37) : error C2065: 'a' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(37) : error C2065: 'nail' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(37) : error C2109: subscript requires array or pointer type 27e5fc42-d41b-42da-9ed8-452e7ff6161d(37) : error C2065: 'nail' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(37) : error C2109: subscript requires array or pointer type 27e5fc42-d41b-42da-9ed8-452e7ff6161d(38) : error C2065: 'b' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(38) : error C2065: 'nail' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(38) : error C2109: subscript requires array or pointer type 27e5fc42-d41b-42da-9ed8-452e7ff6161d(38) : error C2065: 'nail' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(38) : error C2109: subscript requires array or pointer type 27e5fc42-d41b-42da-9ed8-452e7ff6161d(40) : error C2065: 'rope_lenght' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(40) : error C2065: 'a' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(40) : error C2065: 'a' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(40) : error C2065: 'b' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(40) : error C2065: 'b' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(40) : warning C4244: 'function' : conversion from 'int' to 'float', possible loss of data 27e5fc42-d41b-42da-9ed8-452e7ff6161d(40) : warning C4244: '+=' : conversion from 'float' to 'int', possible loss of data 27e5fc42-d41b-42da-9ed8-452e7ff6161d(42) : error C2065: 'a' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(42) : error C2065: 'nail' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(42) : error C2109: subscript requires array or pointer type 27e5fc42-d41b-42da-9ed8-452e7ff6161d(42) : error C2065: 'nail' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(42) : error C2109: subscript requires array or pointer type 27e5fc42-d41b-42da-9ed8-452e7ff6161d(43) : error C2065: 'b' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(43) : error C2065: 'nail' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(43) : error C2109: subscript requires array or pointer type 27e5fc42-d41b-42da-9ed8-452e7ff6161d(43) : error C2065: 'nail' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(43) : error C2109: subscript requires array or pointer type 27e5fc42-d41b-42da-9ed8-452e7ff6161d(45) : error C2065: 'rope_lenght' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(45) : error C2065: 'a' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(45) : error C2065: 'a' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(45) : error C2065: 'b' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(45) : error C2065: 'b' : undeclared identifier 27e5fc42-d41b-42da-9ed8-452e7ff6161d(45) : warning C4244: 'function' : conversion from 'int' to 'float', possible loss of data 27e5fc42-d41b-42da-9ed8-452e7ff6161d(45) : warning C4244: '+=' : conversion from 'float' to 'int', possible loss of data 27e5fc42-d41b-42da-9ed8-452e7ff6161d(47) : error C2065: 'rope_lenght' : undeclared identifier _______________________________________________________________________________________ and this is my program code: _______________________________________________________________________________________ #include <stdio.h> #include <stdlib.h> #define PI 3.1415926535 struct fcoord { float x, y; }; float sqr(float n) { float a = 1, b = n; int i = 1000; while (i--) { a = (a+b)/2; b = n/a; } return a; } int main() { int nail_num, i; float nail_radius; fscanf(stdin, "%d %f", &nail_num, &nail_radius); struct fcoord * nail = (struct fcoord *) malloc(sizeof (struct fcoord) * nail_num); for (i = 0; i < nail_num; i++) fscanf(stdin, "%f %f", &(nail[ i ].x), &(nail[ i ].y)); float rope_lenght = 0, a, b; rope_lenght += (2 * PI * nail_radius); for (i = 0; (i+1) < nail_num; i++) { a = nail[ i ].x-nail[ i+1 ].x; b = nail[ i ].y-nail[ i+1 ].y; rope_lenght += sqr((a*a) + (b*b)); } a = nail[ nail_num-1 ].x - nail[ 0 ].x; b = nail[ nail_num-1 ].y - nail[ 0 ].y; rope_lenght += sqr((a*a) + (b*b)); fprintf(stdout, "%.2f\n", rope_lenght); return 0; } _______________________________________________________________________________________ Please help! Edited by author 25.08.2012 12:30 #include<stdio.h> int power(const int a,const int b) { int k=0,num=1; for(k=0;k<b;k++) { num=num*a; } return num; } int foc(int a) { if(a==1) { return 1; } else { return foc(a-1)*a; } } int arr(int a,int b) { if(!b) { return 1; } else { return foc(a+b)/(foc(a)*foc(b)); } } int main(void) { int n=0,k=0,i=0,sum=0; scanf("%d",&n); scanf("%d",&k); for(i=0;n-i>=i;i++) { if(!i) { sum=sum+power(k-1,n); } else if(i==1) { sum=sum+(n-1)*power(k-1,n-1); } else { sum=sum+arr(i,n-2*i)*power(k-1,n-i); } } printf("%d\n",sum); return 0; } test results: N K result 3 10 891 4 10 8829 5 10 87480 6 10 866781 7 10 8588349 8 10 85096170 2 2 2 3 8 441 5 9 50688 I'll appreciate it if you find the dead test and point my bug out,thank you! By the way,I get the WA at test#2. Edited by author 16.11.2010 20:38 import java.util.Scanner; import java.util.Arrays; public class T_1009 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] m = new int[n+1]; // Dynamic m[1] = k-1; m[2] = k*(k-1); for (int i = 3; i <=n; i++) { m[i] = (m[i-1]+m[i-2])*(k-1); } System.out.print(m[n]); } } for k = 2, n = 2 Enigma [UB of TUIT] programm write 3, but right answer 2, because: 10 11 On 21 th test N=100000 R=0 Edited by author 24.08.2012 18:03 |
|