Общий форум#include <iostream> using namespace std; int main() { int a[1000]; int n=0,s,sx=0,m=0; cin >> n; for(int i=0;i<n;i++){ cin >> a[i]; } for(int u=1;u<n-1;u++){ s=a[u]+a[u+1]+a[u+2]; if(s>sx){ sx=s; m=u+1; }} if (n==3){ sx=a[0]+a[1]+a[2]; m=2; } cout << sx << " " << m << endl; } #include<iostream> using namespace std; int main() { int numSection; cin >> numSection; int a[numSection]; for (int i = 0; i < numSection; i++) { cin >> a[i]; } int n = numSection - 3 + 1; int max = 0; int middleNumSec = 0; for (int i = 0; i < n; i++) { if (i + 3 > numSection) { break; } int sum = 0; for (int j = i; j < i + 3; j++) { sum += a[j]; } if (sum > max) { max = sum; middleNumSec = i + 2; } } cout << max << " " << middleNumSec << endl;
system("pause"); return 0; } My solution: #include <iostream> #include <string> #include <vector> #include <set> #include <queue> #include <map> #include <stack> #include <algorithm> #include <bitset> #include <cstring> #include <cmath> #include <cstdlib> #include <cstdio> #include <iomanip> #define F first #define S second #define ll long long #define len length() #define sqr(x) x*x #define pb push_back #define mp make_pair #define sz(x) ((int) (x).size()) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define bp(x) __builtin_popcount(x) #define INF numeric_limits<long long int>::max() #define frp freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++) const int maxn = (int)1e6; const int mod = (int)1e9 + 7; using namespace std;
int n; int a[maxn]; int sum,ans; int cnt; main(){ scanf("%d",&n); for(int i=1; i <= n; i++){ scanf("%d",&a[i]); } for(int i=1; i <= n-2; i++){ sum=a[i]+a[i+1]+a[i+2]; if(ans < sum){ ans=sum; cnt=i+1; } } printf("%d %d",ans,cnt);
return 0; } OMG man, thank u) this is correctly #include <iostream> using namespace std; int a[1000], n = 0, s, sx = 0, m = 0; void main() {
cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int u = 0; u < n; u++) { s = a[u] + a[u + 1] + a[u + 2]; if (s > sx) { sx = s; m = u + 2; } } For those who as I has wa3 or wa5 and don't understand why: 1) similar must be personal number, not passwords 2) personal number is decimal number 3) to get other password (i.e. calculate diffeence of passwords) we can ONLY change digit, we can't insert or erase digits like in personal number May be you don't have theese mistakes, but I spent a day to undestand it Speed is not constant. It can be 0 or infinity. But it covers each k kilometers in h hours. So, for a segment of length less than k, minimum time is 0 and maximum time is h. Edited by author 06.06.2019 14:01 Can somebody give me some hard test - my program works fine on all tests, which I can think out. BTW, here is some of them: ######## #.OOOOO# #$O$O$O# #OO$O$O# #@O$O$O# ###***O# #......# ######## ######## #.O$OO.# #O$..$O# #$$..$O# #O$..$$# #@$O.$O# #..$OO.# ######## ######## #.O$OO.# #O$..$O# #$$..$O# #O$..$$# #@$..$O# #.O$OO.# ######## ######## #......# ###***O# #@O$O$O# #OO$O$O# #$O$O$O# #.OOOOO# ######## ######## #.....O# #$$$$$O# #OO...O# #$$$$$O# #O.OO$.# #.O$.$+# ######## ######## #......# ###***O# #@O$O$O# #OO$O$O# #OO$O$O# #OOOOOO# ######## ######## #.$.$OO# #@OOOOO# #O$$$$$# #O.....# #$$$$$$# #......# ######## ######## #.OOO.O# #@$O##O# #OOO*OO# #.$O$O$# #$$$$..# #...OOO# ######## ######## #OOOO.O# #@OO##O# #OOO*OO# #.$O$OO# #$$$$.O# #...OOO# ######## ####### #@$OO.# #$O$OO# #.O.OO# ####### P.S. space I've changed to O. Edited by author 03.11.2009 20:42 AC finally. I have TLE 62 too. Don't have ideas of how to proceed. Can you give a hint of how you have improved you program to pass this test? I've stored only those positions, which can not be processed in some steps by greedy algo + store only positions, where man is in lowest-left cell + stop, when position is surely bad (I've used a lot of classes of bad positions) + make moves, that is surely necessary. Hi Oracle, can u give us some cases that considered as a bad position? I have a prunning issue also on my solution #include "stdafx.h" #include <iostream> int main() { int a; int b; int c; scanf_s("%d%d\n", &a, &b); c = a + b; printf("%d\n", c); return 0; } Зачем тебе эти директивы вообще? Нужна только айострим. И пишется так: <stdafx.р> #include <iostream> using namespace std; int main() { long long a, b; cin >> a >> b; cout << a+b; } Hi guys, i've tried to solve this problem with A*. I came with pull distance as heuristic and calculate the distance table with Floyd's algorithm. I also have put deadlock detector (for Simple and Frozen) on my code. Is there something i miss? Or do you have any other suggestion? I am very happy if i can discuss with you guys. Thanks before for your help :) I know some interesting optimisations which helped me get TLE 78 but I don't understand how to use A* in this problem. Let's discuss it. My email is imoskovchenko72@gmail.com I tried to pick up to my occasion all data types ,but there was some problem ;Then i tried using data type "auto" and it's worked! I got WA#19 too! Any tricky test here? test 19 is like this 2 1 1 101 101 2 1 Your answer is probably 0 The right one is 1 Thank you, that was really helpful! Whoever made this problem, thanks a lot! Seeing group theory applied in cp felt pretty cool. Alos learnt a lot thanks to this problem I believe I am having precision errors when calculating the solution. I changed from doubles to long doubles and got one more test case, so I believe my solution is correct but not precise enough. Any tips to resolve this? Never mind, there was simplification in the calculations and then I just hard-coded printed out the decimals. This problem is just cancer Yes Some tests: a = 1 ans = 3.666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667 a = 1.5 ans = 5.666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667 a = 666 ans = 2663.66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666674 a = 1000000000000000000 ans = 3999999999999999999.666666666666666666666666666666666666666666666666666666666666666333333333 Edited by author 03.06.2019 20:30 have no ideas. i've runned my random test generator and my program passed over 1000 tests, but wa. help, please. This hand-made test helped me with WA#16: 5 3 1 2 -2 4 3 2 4 2 -1 The possible answer is: Possible 0 1 3 0 2 Good luck. Глащенко Никита, thank you very much! Really useful test! can anybody help me with this problem? can somebody tell what kind of test is it Check array sizes. i have already checked. all right. maximum number of participants is 300. [code deleted] Edited by moderator 19.11.2019 23:09 Maybe you found the error, but i got stuck on this problem and tried your solution. I hoped to find the problem of my submission. When there are 300 different names without Isenbaev, your program added Isenbaev with number 301 and crashes because of the array index > 300 setting array to [1..301] did the trick and AC thank you! your reply help me a lot! thank you, you saved my day 1) Maybe, you are reading long long variable with this command : scanf("%d",&arr[i]); It is not right. You should do, for example, it with next command scanf("%I64d",&arr[i]); 2) Maybe, you were confused by statement. You have to choose such two points so line that passing through this points has maximal absolute value of inclination, not just inclination. 3) Maybe, you are doing something like this : for ( int i = 1 ; i <= n ; ++i ) { long long d = abs2(arr[i+1] - arr[i]); if ( d > x ) { x = d; m1 = i; } } There is a mistake in first line. Right way is for ( int i = 1 ; i < n ; ++i ) { It was my biggest mistake, because the problem itself is so simple. Thannnnnnnnnnnnnnnnnk youuuuuuuuuuuuuu verrrrrrrrrrrrry mucccccccccccccch! Thannnnnnnnnnnnnnnnnk youuuuuuuuuuuuuu verrrrrrrrrrrrry mucccccccccccccch! Thanks a lot! The definition of inclination is ambiguous in the problem statement. Thanks a lot! I have ignored "absolute value" too. Thannnnnnnnnnnnnnnnnk youuuuuuuuuuuuuu verrrrrrrrrrrrry mucccccccccccccch! Thannnnnnnnnnnnnnnnnk youuuuuuuuuuuuuu verrrrrrrrrrrrry mucccccccccccccch! Problem statement says "His friends write numbers from 1 to N on cards", but it doesn't mention that these numbers should be distinct. Yet, it seems like the problem only accepts solutions in which the numbers are distinct (i.e. the numbers on the N cards are a permutation of [1..N]). Since you're able to download it, you can actually decompile it and submit the code to get accepted. There's a Thread.Sleep(3000) in there that you'll need to comment out. The cases when all times are less than 6 seconds are neglected. So the cost of each plan should be zero as all calling will be free but adding the basic plan to the cost leads to AC. puts gets.split(' ').sum { |s| s.to_i } а вот так ок: puts gets.split(' ').map { |s| s.to_i }.inject(0) {|sum,x| sum + x } что не так с с sum? Edited by author 22.05.2019 11:43 Edited by author 29.05.2019 02:44 |
|