Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | I got AC! Here is my program! | panrui | 1197. Один в поле воин | 27 янв 2015 03:32 | 8 | #include<iostream.h> int t[12][2]; int a,b; void print() { int s,x,y,i; s=0; for (i=1;i<=8;i++) { x=t[i][1]; y=t[i][2]; if ((b+x>=1) && (b+x<=8) && (a+y>=1) && (a+y<=8)) s++; } cout<<s<<endl; } void in() { t[1][1]=2;t[1][2]=1; t[2][1]=1;t[2][2]=2; t[3][1]=2;t[3][2]=-1; t[4][1]=-1;t[4][2]=2; t[5][1]=-2;t[5][2]=1; t[6][1]=1;t[6][2]=-2; t[7][1]=-1;t[7][2]=-2; t[8][1]=-2;t[8][2]=-1; } void main() { int n,i,j; char p; cin>>n; in(); for (i=1;i<=n;i++) { cin>>p; a=int(p)-96; cin>>p; b=int(p)-48; print(); } } #include <stdio.h> int p[8][8]={2,3,4,4,4,4,3,2, 3,4,6,6,6,6,4,3, 4,6,8,8,8,8,6,4, 4,6,8,8,8,8,6,4, 4,6,8,8,8,8,6,4, 4,6,8,8,8,8,6,4, 3,4,6,6,6,6,4,3, 2,3,4,4,4,4,3,2}; void main(void) { int N; scanf("%i\n",&N); for(int i=0;i<N;i++) { char letter,digit; scanf("%c%c\n",&letter,&digit); int il,id; il=letter-'a'+1; id=digit-'0'; printf("%i\n",p[il-1][id-1]); } } #include <iostream> using namespace std; long mz (long xx,long yy) { if ((xx<1)||(xx>8)) return (0); if ((yy<1)||(yy>8)) return (0); return (1); } int main () { long n; char str[100]; long x,y,xx,yy; long i,total; cin>>n; for (i=0;i<n;i++) { cin>>str; total=0; x=(long)(str[0])-96; y=(long)(str[1])-48; xx=x+2; yy=y+1; if (mz(xx,yy)) total++; xx=x-2; yy=y+1; if (mz(xx,yy)) total++; xx=x-2; yy=y-1; if (mz(xx,yy)) total++; xx=x+2; yy=y-1; if (mz(xx,yy)) total++; xx=x+1; yy=y+2; if (mz(xx,yy)) total++; xx=x-1; yy=y+2; if (mz(xx,yy)) total++; xx=x-1; yy=y-2; if (mz(xx,yy)) total++; xx=x+1; yy=y-2; if (mz(xx,yy)) total++; cout<<total<<endl; } return (0); } 这个比较罗嗦的 pls can somebody tell me why i got compilation error on this code #include <stdio.h> #include <stdlib.h> inline int numberOfAttackedFields(int x, int y) { int i = 0; if (x - 1 > 0 && y - 2 > 0) { i++; }
if (x + 1 < 9 && y - 2 > 0) { i++; }
if (x + 2 < 9 && y - 1 > 0) { i++; }
if (x + 2 < 9 && y + 1 < 9) { i++; }
if (x + 1 < 9 && y + 2 < 9) { i++; }
if (x - 1 > 0 && y + 2 < 9) { i++; }
if (x - 2 > 0 && y + 1 < 9) { i++; }
if (x - 2 > 0 && y - 1 > 0) { i++; } return i; } int main(void) { int x, y, n; char input[3]; char firstLetter; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s", input); input[2] = '\0';
firstLetter = input[0];
//lower case if (firstLetter - 'a' >= 0 && firstLetter - 'a' <= 8) { x = firstLetter - 'a' + 1; } //upper case else { x = firstLetter - 'A' + 1; }
//replace the first letter with 0 input[0] = '0'; y = atoi(input); printf("x=%d y=%d\t%d\n", x, y, numberOfAttackedFields(x, y)); }
return 0; } it compiles with no problems on my MAC. I recieve compilation error on any code I submit! But no problems on my side. (...) int main() { int t; scanf("%d",&t); getchar(); while(t--){ char a[10]; scanf("%s", a); int count = 0; if(a[0]-96-2>0 && a[1]-48-2>0) count+=2; else{ if(a[0]-96-1>0 && a[1]-48-2>0) count+=1; if(a[0]-96-2>0 && a[1]-48-1>0) count+=1; } if(a[0]-96+2<9 && a[1]-48-2>0) count+=2; else{ if(a[0]-96+1<9 && a[1]-48-2>0) count+=1; if(a[0]-96+2<9 && a[1]-48-1>0) count+=1; } if(a[0]-96-2>0 && a[1]-48+2<9) count+=2; else{ if(a[0]-96-1>0 && a[1]-48+2<9) count+=1; if(a[0]-96-2>0 && a[1]-48+1<9) count+=1; } if(a[0]-96+2<9 && a[1]-48+2<9) count+=2; else{ if(a[0]-96+1<9 && a[1]-48+2<9) count+=1; if(a[0]-96+2<9 && a[1]-48+1<9) count+=1; } cout<<count<<endl; } return 0; } program Project1; {$APPTYPE CONSOLE} uses SysUtils; var i,j:integer; kolvo, x,y,otvet: longint; koord:string; alpha:string; begin {$IFNDEF ONLINE_JUDGE} assign(input, 'input.txt'); reset(input); assign(output, 'output.txt'); rewrite(output); {$ENDIF} alpha:='abcdefgh'; readln(kolvo); //ff for i:=1 to kolvo do begin otvet:=0; readln(koord); for j:=1 to 8 do if koord[1]=alpha[j] then y:=j; x:=strtoint(koord[2]); if ((x-2)>=1) and ((y-1)>=1) then otvet:=otvet+1; if ((x-1)>=1) and ((y-2)>=1) then otvet:=otvet+1; if ((x-2)>=1) and ((y+1)<=8) then otvet:=otvet+1; if ((x-1)>=1) and ((y+2)<=8) then otvet:=otvet+1; if ((x+2)<=8) and ((y-1)>=1) then otvet:=otvet+1; if ((x+1)<=8) and ((y-2)>=1) then otvet:=otvet+1; if ((x+2)<=8) and ((y+1)<=8) then otvet:=otvet+1; if ((x+1)<=8) and ((y+2)<=8) then otvet:=otvet+1; writeln(otvet); end; {$IFNDEF ONLINE_JUDGE} close(input); close(output); {$ENDIF} end. #include <iostream> #include <stdio.h> #include <vector> using namespace std; class Place { public: char x; int y;
bool isOnboard() { if (x < 'a' || x > 'h' || y < 1 || y > 8) return false; return true; }
Place(char x, int y) { this->x = x; this->y = y; }
}; int main(int argc, const char * argv[]) { int N; cin >> N;
vector<Place> places;
for (int i = 0; i < N; i++) { char x; int y; cin.get(x);
if (x == '\n') { i--; continue; }
cin >> y;
Place place (x, y); places.push_back(place);
}
for (int i = 0; i < N; i++) { Place place = places[i]; int moves = 0;
//left 2 up 1 place.x -= 2; place.y -= 1; moves += place.isOnboard();
//left 2 down 1 place.y += 2; moves += place.isOnboard();
//right 2 down 1 place.x += 4; moves += place.isOnboard(); //right 2 up 1 place.y -= 2; moves += place.isOnboard(); //right 1 up 2 place.x -= 1; place.y -= 1; moves += place.isOnboard(); //left 1 up 2 place.x -= 2; moves += place.isOnboard(); //left 1 down 2 place.y += 4; moves += place.isOnboard(); //right 1 down 2 place.x += 2; moves += place.isOnboard();
cout << moves << endl;
}
} Edited by author 24.01.2014 20:05 This is simply a bruteforce solution, but it is pretty clear though. ;) #include <iostream> using namespace std; int check(int r,int c) { int counter=0; if((r-1)>=0&&(c-2)>=0) counter++; if((r-1)>=0&&(c+2)<=7) counter++; if((r+1)<=7&&(c-2)>=0) counter++; if((r+1)<=7&&(c+2)<=7) counter++; if((c-1)>=0&&(r+2)<=7) counter++; if((c-1)>=0&&(r-2)>=0) counter++; if((c+1)<=7&&(r-2)>=0) counter++; if((c+1)<=7&&(r+2)<=7) counter++; return counter; } int main() { char v; int h,i,vint,n; cin >> n; for(i=0;i<n;i++) { cin >> v>>h; h--; vint=int(v)-97; cout<<check(h,vint)<<endl; } } | | A very nice tip that this problem had for me! | kerpoo | 1208. Соревнование легендарных команд | 27 янв 2015 02:10 | 1 | I was getting TLE because it's bigget input is too small :) It had a very nice tip: nC2 > 3*nlogn (n>25) & nC2 <= 3*nlogn (n<25) The maximum n was 18 so 18C2=153 > 3*18log18=216 and in a normal mode we often prefer nlogn solutions to n^2 solutions. But in this problem max n was 18 and I tried many times to optimize my brute force solution (I was getting TLE for few extra ms) to get AC and I couldn't see the tip because n was so small :) My 2^n*nC2 solution got AC but my 2^n*3*nlogn solution got TLE. Edited by author 29.01.2015 13:48 | | Python 2.7 - how to get input data and print output - anybody can provide an example? | rsolera | 1002. Телефонные номера | 26 янв 2015 18:17 | 1 | Hi, My program solves (in my laptop) all the test problems I have found in the forum, however I get wrong answer for the first test. I think my problem could be in the input or output part of my program. Could anybody who has passed the problem using python 2.7 post the reading and printing part of his program? Thanks a lot, | | read input in python | crc | 1006. Квадратные рамки | 25 янв 2015 02:56 | 1 | Hi, I get runtime error with my program. I am almost sure that it is some problem with reading the input. I have tested my program with many examples and always get the right answer. This is what I use to read the input: for y,line in enumerate(stdin.read().split()): for x,char in enumerate(line.decode('utf8')): c=ord(char) ....... I had to use decode('utf8') otherwise I got some strange characters. But now the number I get from ord(char) are not the codes given in the problem. Thanks. | | ToAdmin-WA#7 | REVERSER | 1641. Дежурства | 24 янв 2015 23:54 | 1 | hi i tougth my code is correct,but it wrong on test7,plz give me a test case 7 ty | | Test 42 | Al.Cash | 1843. Разрезание параллелепипеда | 24 янв 2015 23:18 | 1 | I figured out this test has cuts in no more than 2 directions, but still don't understand what causes WA there. | | thanks for interesting task | kasarino | 1142. Отношения | 24 янв 2015 14:01 | 1 | Thanks to the author for the interesting task in combinatorics and integer partitioning! | | Why WA #2 | Najmaddin Akhundov | 2005. Такси для программистов | 24 янв 2015 10:12 | 3 | Why WA #2 Najmaddin Akhundov 20 ноя 2014 04:15 [code deleted] Edited by moderator 19.11.2019 23:01 I got it. If there are two possible answer, only 1 of them should be printed. If there are two possible answer, only 1 of them should be printed. Thanks...!!! | | It is very simple problem | Dima_Philippov | 1470. НЛО | 23 янв 2015 16:56 | 3 | Just write 3d Fenvick Tree. And nothing more. May be you mean "exclusion & inclusion"? | | When rounding (particularly test 13) | Roger Collins | 1820. Уральские бифштексы | 23 янв 2015 11:00 | 1 | Pay attention to your data types, and convert before ceil if needed. | | WA #10 (1014 GCC 4.9) | kh1024 | 1014. Произведение цифр | 23 янв 2015 05:52 | 2 | (source removed after AC) Edited by author 23.01.2015 06:01 Resolved issue. Hints for those who look at this for reference. While this may not be the most elegant solution, it works. Make sure that: - Large values work. Try to imagine how many digits your solution could be composed of... - Values that may result in a legal (0-9) divisor at first, followed by a prime number... - As stated before, 0 and 1. Remember it's the LEAST positive integer... Edited by author 23.01.2015 06:00 | | WA #2 | Andrew | 1001. Обратный корень | 23 янв 2015 01:26 | 1 | WA #2 Andrew 23 янв 2015 01:26 #include<iostream> #include<vector> #include<iomanip> using namespace std; void main() { vector<double> br; double n; char c; while( (c=getchar()) != '\n') { cin >> n; br.insert(br.begin(), sqrt(n)); } for(int i = 0; i < br.size(); i++) cout << fixed << setprecision(4) << br[i] << endl;
} | | Problem Statement...... | Jaideva | 1355. К вопросу о лысине | 22 янв 2015 01:28 | 2 | ".....one could pass from the pub number n to the pub with a number that divides n....." I think it should be..... ".....one could pass from the pub number n to the pub with a number that is divisible by n" otherwise it's just wrong.... Agreed, was looking if someone else had noticed. Edited by author 22.01.2015 01:28 | | Which STL to use? | Alibi | 1494. Монобильярд | 21 янв 2015 10:46 | 1 | In this task you can use stack!!!! | | why&i think solutions are same&& | Arseniy | 1877. Велосипедные коды | 21 янв 2015 10:06 | 3 | #include <stdio.h> using namespace std
void main() { __int64 a,b,i,f=0; scanf("%i64d",&a); scanf("%i64d",&b); if( ((a % 2)==0) || ( ( b % 2)== 1)) printf("yes"); else printf("no"); } it has wa32 on c But same alghoritm on delphi has ac& program Project2; {$APPTYPE CONSOLE} uses SysUtils; var a,b:integer; begin readln(a); readln(b); if( ( ( a mod 2 )= 0 ) or ( (b mod 2) = 1) ) then write('yes') else write('no'); end. Chto za fignya? Scanf can sometimes convert integers to octal. ie. 0132 | | WA #8 time limit exceeded | Al Alamin | 1196. Экзамен по истории | 21 янв 2015 03:54 | 2 | Does any one have a faster code of python than this p=int(input()) plist=set() for i in range (p): a=int(input()) plist.add(a) s=int(input()) slist=[] count=0 for i in range (s): a=int(input()) if a in plist: count+=1 print (count) I've no idea how to make it faster. Got stuck myself. | | What is test 1 | Hakkinen | 1008. Кодирование изображений | 21 янв 2015 02:24 | 3 | I TLE on test 1. What is the test 1 Thank you. | | Any hint when there is no healers | panyong0202 | 1952. Убить дракона | 20 янв 2015 15:18 | 2 | Oh, there are no such cases. There is at least one healer and one attacker. Fixed in statement now. | | чтение данных | lucshiiiulian | 1026. Вопросы и ответы | 18 янв 2015 20:32 | 2 | алгоритм сделал и работает, но не проходит проверку, говрит что напечатал слишком много букафф,,, мне кажется я неправильно читаю К, не знаю как перепрыгнуть через те решетки :( int K; char ch; scanf("%s%d",&ch,&K); | | тест 19 | CrispyArty | 2009. Очереди в столовой | 17 янв 2015 21:05 | 2 | тест 19 CrispyArty 29 май 2014 12:39 Не могу понять что не так с 19-ым тестом... Даёт "Wrong anser" хотя я проверил каждую мелочь... кто может помочь? I had this problem too, because of a logic problem... Test: 9 2 0 0 0 0 2 0 2 0 6 0 6 0 8 0 10 6 1 2 3 4 5 6 11 3 7 8 9 Ans: 11 right 11 left 12 right 15 left 14 left 12 left 13 right 13 left 14 right |
|
|