Общий форумLet 0,1,2,..N-1 - outer door N .. 2*N - 1 - 1-inner room doors 2*N .. 3N - 1 - 2-inner room doors .... i*N i*N + 1, .. i*N + N-1 - i-th room doors total (K+1)*N doors. W[i][j] - minimum dist from i to j-th door, where 0 <= i,j < (K+1)*N initially W[i][i] = 0, W[i][j] = inifinity for i <> j. read, and set W[i][j] = 1 if there exists road from i to j doors. ----------------- N times run following steps: 1. Floyd algorithm for 0.. (K+1)*N - 1 doors.
2. for 1<= t <= K , 0 <= i, j < N update W[t*N + i][ t*N + j] = min(W[t*N + i][t*N+j], W[i][j]) Because (t*N + i, t*N + j) - is identical path as outer (i,j) path.
Edited by author 31.10.2020 16:46 8 8 1 2 3 4 5 6 7 8 21 4 2 1 3 3 4 2 2 3 3 4 1 1 3 4 1 2 2 But n must be divisible by 3 I have written the code the using user defined function thats why it has become much bigger. #include<Stdio.h> #include<math.h> int Sn(int n); int An(int a); int main() { int x; scanf("%d",&x); Sn(x); } int Sn(int n) { int j; if(n==1) {An(1); printf("+1");} else { for(j=1;j<n;j++) printf("("); for(j=1;j<=n;j++) {if(j==1) {An(j);printf("+%d)",n);} else if(j!=n) {An(j);printf("+%d)",n-j+1);} else {An(j);printf("+1");}}} } int An(int a) { int i,p; if(a==1) printf("sin(%d)",a); else {for(i=1;i<=a;i++) { p= pow(-1,i+1); if(i==1) printf("sin(%d",i); else if(p==1) printf("+sin(%d",i); else printf("-sin(%d",i);} for(i=0;i<a;i++) printf(")"); } } Edited by author 29.10.2020 21:19 Try this test: input: 1 8 output: 1 Oddly enough, my solution printed "infinity" in this simple case, but was successful with first 35 tests That is not a correct input,n >= 3. /* * Author : Arman Sykot * Date & time : 28.10.2020 21:47:12 +06 */ #include <bits/stdc++.h> #define ll long long #define the_flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) using namespace std; int main() { the_flash; int n; cin >> n;
int arr[n][n];
for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cin >> arr[i][j]; }
for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { cout << arr[i - j][j] << " "; } }
for (int i = n; i < 2 * n - 1; i++) { for (int j = n - 1; j >= i - (n - 1); j--) cout << arr[j][i - j] << " "; }
cout << "\n";
return 0; } If you are trying to flip signs on rectangles consider of using 1 request instead of many. :) o_o Edited by author 10.11.2020 12:55 Hi everyone! If you are getting TLE in Test #2 or maybe another, I would like to give you a little help: -> Test #2 seems to give large numbers (like 15000), and it gives you those numbers in increasing order. Think about it. Now, if that isn't enogh, I can give you a little more help: -> Create an array / vector / list which will store the prime numbers you find. -> Create an algorithm that determines whether a number is prime or not (remember to only compare with odd numbers smaller than the square root of the number from which you are trying to figure out its primality). -> Create a function that calculates the n-th prime number. For that create a counter which increases everytime you find a new prime number and store that prime number in your array / vector / list. -> Finally, remember the thing I said at the beginning of this post! :D Hope it helps. :D since it's recent enough, that gives some hope... honestly, i've done all of listed above, and yet it gives TLE. i'm so done with this... please help... i don't understand why. maybe somebody could help... here's the code from math import sqrt n=int(input()) l=0 a=[None]*n b=[None]*n for k in range(n): a[k]=int(input()) for z in range(n): p=0 for i in range(n): if a[i]>p: p=a[i] l=i b[z]=n-1-l a[l]=-a[l] for z in range(n): a[z]=-a[z] while n>1: n=n-1 a[b.index(n-1)]=2*sqrt(a[b.index(n)]*a[b.index(n-1)]) print('{:.2f}'.format(a[b[0]])) Edited by author 27.10.2020 23:40 dp[N][N] - minimum number of added brackets, ok[l][r] - is [l, r] already solved, vector<pair<char, int>> add[N][N] - what and where brackets should be added to [l][r], to make it balanced. make calc(l, r) function, if ok[l][r] then return dp[l][r], if(l == r) then add[l][r] = {{reversed(s[l]), l}} dp[l][r] = 1 if(l + 1 == r and s[l] matches s[r]) then dp[l][r] = 0 if(s[l] == s[r]) you update dp[l][r] with dp[l + 1][r - 1] or with dp[l][k] + dp[k + 1][r], take care of already balanced strings Precompute the results for ~200 numbers (at regular intervals) and hardcode them. Then you can just bruteforces starting from the closest precomputed number. Yea, this works fine, but how to solve it fairly? Use 64 bit integer for resulting value. Initially I didn't believe result can be this big and spent a lot of time looking for another possible issues with code. I am checking possibility of shot, I am checking edge case (when shot just touches the tank). My geometry calculations use epsilon (also tried to adjust epsilon, didn't help). Tried to output results with 7 decimals. I am using double. What else I could miss? Are you sure that the size of your epsilon is enough? The angle might be too small. Place the tank and players on opposite sides of the map, and check your solution. Edited by author 23.10.2020 13:36 import java.util.Scanner; import java.math.RoundingMode; import java.text.DecimalFormat; public class Misol1001{ public static void main(String[]args){ Scanner i=new Scanner(System.in); DecimalFormat df = new DecimalFormat("#.####"); df.setRoundingMode(RoundingMode.CEILING); int a=i.nextInt(); long[] k=new long[a]; for(int j=0; j<a; j++){ k[j]=i.nextLong(); } double[] l=new double[a]; for(int c=0;c<a; c++){ l[c]=Math.sqrt(k[c]); } for(int j=a-1; j>=0; j--){ System.out.println(df.format(l[j])); } } } I got wrong answer beacuse of test 6 Someone please explain what is test 6 Program in C #include <stdio.h> #include <math.h> int main() { long int n,m,y; int x,cont=0,aux1; scanf("%d %d %d",&n,&m,&y); for (int i = 0; i <=m-1 ; ++i) { aux1=pow(i,n); if (aux1%m == y) { printf("%d ",i); cont++; } } if (cont == 0) { printf("-1\n"); } return 0; } Edited by author 13.10.2020 05:27 В описании обоих примеров мы делаем одно и то же: 1. Расшифровали 2. Перевернули 3. Зашифровали 4. Показали. Зачем нам данные о типе компьютера GOOD или BAD? What is wrong with my code? :( #include <stdio.h> #include <stdlib.h> int main (){ int N; scanf ("%d",&N); for (int i = 0 ; i < N ; i++){ char x; int y; getchar(); scanf ("%c %d",&x,&y); int movimientos = 0;
if (y + 2 <= 8) if (x - 1 >= 97){ movimientos++; }
if (y+2 <=8) if (x + 1<=104){ movimientos++; } if (y-2 >= 1) if (x-1 >97){ movimientos++; } if (y-2 >= 1) if (x + 1 <= 104){ movimientos++; }
if (x+2 <= 104) if (y - 1 >= 1){ movimientos++; } if (x+2 <= 104) if (y+1 <= 8){ movimientos++; } if (x-2 >= 97) if (y+1 <= 8){ movimientos++; } if (x-2 >= 97) if (y-1 >= 1){ movimientos++; } printf ("\n %d", movimientos); printf ("\n"); }
return 0; } Edited by author 21.10.2020 01:36 Edited by author 21.10.2020 01:37 just had to consider from 'a' 'h' and '1' '8' Can anybody give me ideas about 21 test, please? Edited by author 18.10.2020 22:11 Edited by author 19.10.2020 03:42 |
|