Common BoardI always get WA in #5 here is my code, somebody help me please. <code> #include<stack> #include<iostream> #include<algorithm> #include<vector> #include<list> #include<iterator> using namespace std; int getSafe(vector<string> a,int an, vector<string> b, int bn){ int d=0; for(int i=0;i<an;i++){ for(int j=0;j<bn;j++) if(a[i]==b[j]){ d++; break; } } return d; } struct ve{ vector<string> v; }; int main(){ int n,N,m; cin>>N; string str; vector<string> menu; for(int i=0;i<N;i++){ cin>>str; menu.push_back(str); } cin>>n; int a,b; cin>>b; vector<string> fMenu; for(int i=0;i<b;i++){ cin>>str; fMenu.push_back(str); } int i=0; int nums[102]; ve res[102]; while(i<n){ cin>>a; nums[i]=a; for(int j=0;j<a;j++){ //cout<<"d"; cin>>str; //cout<<"s"; res[i].v.push_back(str); } i++; } cin>>m; for(int i=0;i<n;i++){ int x=getSafe(res[i].v,nums[i],fMenu,n); int c=getSafe(menu,N,res[i].v,nums[i]); if(x-nums[i]==0) cout<<"YES\n"; else if(N-b-nums[i]+x-m<0) cout<<"NO\n"; else cout<<"MAYBE\n"; } return 0; } </code> кто-нибудь знает какой 3 ий тест ? Уже 7ой раз на нем фейлится, long'и использую. Edited by author 18.05.2014 18:13 Edited by author 18.05.2014 18:13 #include <stack> #include <cmath> using namespace std; int main() { double n; stack<double> numbers; while (scanf("%lf", &n) != EOF) numbers.push(n); while (!numbers.empty()) { printf ( "%.4f\n", sqrt( double(numbers.top()) ) ); numbers.pop(); } return 0; } Yep! Read and parse input manually, scanf is expensive, %lf is even more expensive. As a bonus, you would not have to store read doubles. What surprised me is that printf is even much more expensive, so if you can create text representation of a double in given format - you are welcome! I have just got 0.031s execution time, what is yours? #include <iostream> #include <vector> #include <math.h> #include <stdio.h> using namespace std; int main() { vector<int> v; int value; while(true) { cin >> value; if(cin.eof()) { break; } else if(cin.fail()) { cin.clear(); // 清空错误状态 cin.ignore(); // 忽略掉下一个字符 continue; } else if(value >= 0) { v.push_back(value); } } cout << fixed; cout.precision(4); for(vector<int>::reverse_iterator iter = v.rbegin(); iter != v.rend(); ++iter) { if(*iter == 0) cout << (double)0 << endl; else cout << sqrt(*iter) << endl; } return 0; } Do not break on cin.eof(), it may be set even if a good value is read (in case the last line is not terminated by newline, I guess). Or maybe they terminate data by non-numeric symbols? Nobody would say :) Break on if (!cin), do not clear cin. And why do you check for (*iter==0)? It works fine as in general case. thanks... #include <stdio.h> #include <math.h> #define PI 3.1416 int main() { double a, r, area; scanf("%lf%lf", &a, &r); a /= 2; if (a >= r) { printf("%.3f\n", PI * r * r); return 0; } if (r >= sqrt(2) * a) { printf("%.3f\n", 4 * a * a); return 0; } printf("%.3f\n", PI * r * r - 4 * (acos(a / r) * r * r - a * sqrt(r * r - a * a))); return 0; } > thanks... > > #include <stdio.h> > #include <math.h> ?????? You can use integral to calculate the area Instead of using any mathematic function. I should use ".3lf" instead of ".3f" in the format string of printf. > I should use ".3lf" instead of ".3f" in the format string > of printf. #define PI 3.1416 // no #define PI 3.1415926535897932 //yes Better to use standard M_PI Edited by author 17.05.2014 17:54 var a,r:integer; az,s,stru,b:real; function ArcCos ( X : Real ): Real; var tmpArcCos : Real; begin if X = 0.0 then tmpArcCos := Pi / 2.0 else tmpArcCos := ArcTan ( Sqrt ( 1 - X * X ) / X ); if X < 0.0 then tmpArcCos := Pi - tmpArcCos; ArcCos := 180*tmpArcCos/pi; end; begin readln(a,r); if a/2>=r then writeln(pi*r*r:1:3) else if sqrt(2)/2*a<=r then writeln(a*a) else begin az:=2*arccos((a/2)/r); s:=pi*r*r*az/360; b:=2*sqrt((r-a/2)*(r+a/2)); stru:=a/4*b; s:=s-stru; s:=pi*r*r-4*s; writeln(s:1:3); end; readln; end. Edited by author 17.05.2014 17:52 It is easy to put your code, where nothing is clear and say: "Look idiots, how clever I am". Try to help people, instead of showing off yourself. #include <iostream> #include <cmath> #include <stdio.h> int main() { using namespace std; int nRadius, nLenght; double dAnswer, dPi = 3.141592654; cin >> nLenght >> nRadius; if (nRadius * nRadius >= nLenght * nLenght / 2) { dAnswer = nLenght * nLenght; } else if (nRadius <= nLenght / 2) { dAnswer = nRadius * nRadius * dPi; } else { double dX = sqrt(nRadius * nRadius - nLenght * nLenght / 4); double dSg = dPi * nRadius * nRadius / 360 * (360 - 8 * atan2(dX, nLenght / 2) * 57.296); dAnswer = dSg + 4 * nLenght / 2 * dX; } printf("%0.3f", dAnswer); return 0; } Edited by author 31.08.2013 17:00 Edited by author 31.08.2013 17:00 Firstly calculate all in radians, don't even think about degrees, because all of cmath functions works in radians. And you should change all integers to double. Example: change 8 to 8.0 and so on. Use standart pi constant M_PI Check all functions. Edited by author 17.05.2014 17:45 var a:array[1..15000] of longint; i,n,j,k,flag,b,m:longint; k1 :longint; begin k:=0; read(n); read(a[1]);k:=1; if n>1 then begin for i:=2 to n do begin read(b); flag:=0; j:=1; repeat if a[j]=b then begin flag:=1; end; j:=j+1; until (flag=1) or (j>k); if flag=0 then begin k:=k+1; a[k]:=b;end; end; end; read(m); for i:=1 to m do begin read(b); j:=1; flag:=0; repeat if a[j]=b then begin flag:=1; k1:=k1+1;end; j:=j+1; until (flag=1) or (j>n); end; writeln(k1); end. Тайм лимитед на 8 тесте. Что не так?? Где я что прохлопала.... Прохелпите мне, плиз Могу предположить, что программа выполняется слишком долго.У меня такая же штука: на сотые секунды больше выполняется Решение в лоб вряд ли пройдет. Мой алгоритм решения: 1. Легко заметить что сумма цифр от 1 до N может быть вычислена по формуле арифметической прогрессий. 2. Первая цифра всегда один. 3. Нужно найти самую меньшую или равную сумму к нашему К, её легко можно найти использую пункт 1. 4. Если найденная сумма минус К ровно одному то ответ один, иначе ноль. Edited by author 04.05.2012 21:02 Почему вы не можете объяснять внятно, такое ощущение что вы не сами решаете свои задачи! Объясните мне пожалуйста, Как вычислить сумму от 1 до N Если нам только известен an То есть место положения N, но не известен сам N. Ведь формула такова: Sn = a1+an/2*N; Как найти Sn Если нам не известно N ?????... Решение в лоб вряд ли пройдет. Мой алгоритм решения: 1. Легко заметить что сумма цифр от 1 до N может быть вычислена по формуле арифметической прогрессий. 2. Первая цифра всегда один. 3. Нужно найти самую меньшую или равную сумму к нашему К, её легко можно найти использую пункт 1. 4. Если найденная сумма минус К ровно одному то ответ один, иначе ноль. Edited by author 04.05.2012 21:02 Можно положить все возможные позиции в Set, а потом проверять есть ли эта позиция в Set'e. Как заполняется Set: Постепенно суммируем числа начиная от 0 и заканчивая суммой не больше 2^31-1, промежуточные суммы кладем в Set, прибавив перед этим единицу. Будьте внимательны при задании ограничения 2^31-1. Сперва я указал так: 1<<31-1 Но это неправильно, т.к. приоритет у вычитания, а потом у сдвига. Можно указать так (1<<31)-1 или еще проще Integer.MAX_VALUE (оба варианта равнозначны). Я решал задачу с Long, но достаточно и Integer. Edited by author 26.03.2014 01:14 package acm.timus.ru; import java.util.Scanner; public class N_1209 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int i=1,a=0,k=0; for (int j=1; j<=n; j++) { a=sc.nextInt(); if (i<a) { while(i<a){ k++; i+=k; } }else{ while(i>a){ i-=k; k--; } } if (i==a) { System.out.print("1"+" "); } else{System.out.print("0"+" ");}
} } } I use a block of continuous memory, divide the memory into Block(50 int).and each last one of Block is used to store the block number of previous Block in a same stack.moreover,I use two arrays to identify whether the Block is free and to store offset in a Block respectively.Finally, I use an array[1000] to store the number of Block are being used in a stack. Edited by author 16.05.2014 13:38 Please give me some tests for #Wa4 ! Исправьте слово "соледует" в последнем предложении Результата: "соледует вывести единственную фразу «No solution»". How can you do it, I'am puzzled. Can you solve it today??? Edited by author 23.04.2004 11:29 Dijkstra via STL priority_queue<> ~0.25 sec Dijkstra via hand-written heap implemented with change_priority() function ~ 0.125 sec how? First. You can contract all regions in one vertex. Second. You can find shortest distance by regions. Third. Remove useless regions. BFS what was left. I don't agree your opinion.The method can't work out in time.This method I had used to solve,but fail. First. You can contract all regions in one vertex. Second. You can find shortest distance by regions. Third. Remove useless regions. BFS what was left. I don't agree your opinion.The method can't work out in time.This method I had used to solve,but fail. Why? I have impelemnted in O(N*M) --> AC in 0.359 s It's very nice method! I have got AC in 0.203s Try this test: 6 5 1 3 6 3 11111 12222 11112 12222 11112 22222 Correct answer: 7 1 So, after 1st BFS both components stay alive. What would prevent 2nd BFS from going a vertical line and output "6 1" while assumed path yields "6 5"? I'm sorry, but can anybody describe me 2nd BFS? I spent a lot of time trying, but it give me wrong answer on some tests. Now I know that's used colouration. Edited by author 29.04.2004 16:37 So fast !!!!!! I got TLE on test 16 all the time ........ I don't know what does "colouration" mean . Could you explain ? Could you say your way ? Oberon (Yura Znovyak) had told the method very clarity. So fast !!!!!! I got TLE on test 16 all the time ........ I don't know what does "colouration" mean . Could you explain ? Could you say your way ? Thanks . I just uesd 0.187s to get AC ! but i think it's possible that such condition appears: in the first BFS to find shortest distance by Changing Boots,there may be many ways to get the shortest Changes. but these ways are different in shortest way of Walking. So? I do not understand :( in the first BFS to find shortest distance by Changing Boots,there may be many ways to get the shortest Changes First BFS is for shortest distance by Changing Boots Then we throw away all useless regions and use SECOND BFS for shortest way of Walking Of course for each region we store min boot change to get to it. While finding shortest walking distance we almost ignore regions. Why almost: we make jumps only on regions with higher boot changes. So we can avoid saw-like regions. Please, help me. My code: #include <iostream> #include <cstring> #include <cctype> using namespace std; const int MaxSourceSize = 100000; const int MaxBuffSize = 1000; const int nKeyWord = 36; const char *comment_start = "<span class=comment>"; const char *keyword_start = "<span class=keyword>"; const char *string_start = "<span class=string>"; const char *number_start = "<span class=number>"; const char *end_teg = "</span>"; const char KeyWords[nKeyWord][sizeof( "implementation" )] = { "and", "array", "begin", "case", "class", "const", "div", "do", "else", "end", "for", "function", "if", "implementation", "interface", "mod", "not", "of", "or", "procedure", "program", "record", "repeat", "shl", "shr", "string", "then", "to", "type", "unit", "until", "uses", "var", "with", "while" }; int main() { register int i, j, g; char source[MaxSourceSize]; cin.get ( source, MaxSourceSize, 0 ); cin.ignore(); for ( i = 0; source[i]; i++ ) { if ( isalpha ( source[i] ) || source[i] == '_' ) { char buff[MaxBuffSize]; bool itKeyWord = false; for ( g = i, j = 0; isalnum ( source[g] ) || source[g] == '_'; g++, j++ ) buff[j] = tolower ( source[g] ); buff[j] = 0; for ( j = 0; j < nKeyWord; j++ ) if ( !strcmp ( buff, KeyWords[j] ) ) { itKeyWord = true; break; } if ( itKeyWord ) cout << keyword_start; for ( i; isalnum ( source[i] ) || source[i] == '_'; i++ ) cout << source[i]; i--; if ( itKeyWord ) cout << end_teg; } else { if ( isdigit ( source[i] ) ) { cout << number_start; for ( i; isdigit ( source[i] ) || ( source[i] == '.' && source[i+1] != '.' ); i++ ) cout << source[i]; i--; cout << end_teg; } else { switch ( source[i] ) { case '{': { int in = 0; cout << comment_start; for ( ; ; i++ ) { if ( source[i] == '{' ) in++; else if ( source[i] == '}' ) { in--; if ( !in ) {cout << source[i];break;} } cout << source[i]; } cout << end_teg; //i--; };break; case '\\': { if ( source[i+1] == '\\' ) { cout << comment_start; for ( i; source[i] != '\n'; i++ ) cout << source[i]; cout << end_teg; i--; } else { cout << '\\'; } };break; case '\'': { cout << string_start; cout << source[i++]; for ( i; source[i] != '\''; i++ ) cout << source[i]; cout << source[i]; cout << end_teg; };break; case '#': { cout << string_start; i++; cout << "#"; for ( i; isdigit ( source[i] ) || ( source[i] == '.' && isdigit ( source[i+1] ) ); i++ ) cout << source[i]; cout << end_teg; i--; };break; default: { cout << source[i]; };break; } } } } return NULL; } I cann't understand why WA#10. Must I use long double? Please, give me some terrible tests. I got WA on test 10 too. And it's a little bit strange because the algo is simple. Maybe there are some problems with "10 fractional digits"... 0-result must be established in int64 only use 6 permutations for vertices of aim triangle also long double won't help because it's same type as double in VC++ As for 6 permutations, I think there must be only 3. Otherwise we'll consider flip-overs. I cann't understand why WA#10. Must I use long double? Please, give me some terrible tests. long double4 is normal. Use EPS = 0.00000001; if use EPS = 0.00000000001 then get WA11. using System; public class Sum { private static void Main() { string[] tokens = Console.ReadLine().Split(' '); Console.WriteLine(int.Parse(tokens[0]) + int.Parse(tokens[1])); } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace T1 { class Program { static void Main(string[] args) { //List<int> n = new List<int>(); List<long> ans = new List<long>(); long s = System.Int64.Parse(Console.ReadLine()); for (int i = 0; i < s; i++) { int x = int.Parse(Console.ReadLine()); ans.Add(Find(x)); } for (int i = 0; i < s; i++) { Console.Write(ans[i]); Console.Write(" "); } //Console.ReadKey(); } static long Find(long x) { // (a)n^2 + (b)n - (c)2x = 0 // a = 1 // b = 1 // c = 2 * x double a = 1, b = 1, c = - 2 * x + 2; double d = b * b - 4 * a * c; double p = (-b + Math.Sqrt(d)) / 2 * a; return (p - (long) p) > 0 ? 0 : 1; } } } using System; using System.Linq; using System.Text; namespace Sum { class Program { static void Main(string[] args) { int x, p = 0; x = int.Parse(Console.ReadLine()); if (x < 0 && x >= -10000) { for (int i = x; i <= 1; i++) p += i; } else if (x > 0 && x <= 10000) { for (int i = 1; i <= x; i++) p += i; } else p = 1; Console.WriteLine(p); //Console.ReadKey(); } } } using System; using System.Linq; using System.Text; namespace Bicycle_Codes { class Program { static void Main(string[] args) { int c1 = int.Parse(Console.ReadLine()); int c2 = int.Parse(Console.ReadLine()); if (c1 % 2 == 0 || c2 % 2 != 0) Console.WriteLine("yes"); else if (c1 % 2 != 0 || c2 % 2 == 0) Console.WriteLine("no"); //Console.ReadKey(); } } } It is interesting to me is that problem can be solved by max flow algorithm of Ford-Falkerson, or we must use another max flow algorithm? |
|