Common BoardPosting code is not a nice idea. Moreover it is not ideal. Could anyone help me? In general this task is quite hard to make bugs if you know what to do... What is your approach? Написал лобовой вариант и всё равно WA10! Значит, вывод не верен. Кто может подсказать, как выводить ответ?(Форум не помог) #define _CRT_SECURE_NO_WARNINGS #define mk make_pair #include <string> #include <map> #include <iostream> using namespace std; typedef map <string, int> mymap; const int nmax = 100005; mymap t[4 * nmax]; mymap answer[nmax]; string word[nmax]; int cnt[nmax]; int n, m; string w_print[11]; int c_print[11]; mymap Search(int L, int R); int BinaryDown(int L, int R, string s); int BinaryUp(int L, int R, string s); mymap Optimal(mymap map1, mymap map2); void Print(mymap M); void QSort_W(int L, int R); void QSort2(int L, int R); void QSort3(int L, int R); int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> word[i] >> cnt[i]; QSort_W(1, n); cin >> m; for (int i = 1; i <= m; i++) { string s; cin >> s; int L, R; L = BinaryDown(1, n, s); R = BinaryUp(1, n, s); answer[i].clear(); if (L != -1 && R != -1) answer[i] = Search(L, R); } for (int i = 1; i <= m; i++) { Print(answer[i]); if(i!=m) cout<<endl; if(!(answer[i].empty()) && i!=m) cout<<endl; } return 0; } mymap Search(int L, int R) { mymap res; res.clear(); for(int i=L;i<=R;i++) { mymap x; x.insert(mk(word[i],cnt[i])); res=Optimal(res,x); } return res; } void Print(mymap M) { int n = 0; for (mymap::iterator it = M.begin(); it != M.end(); it++) { w_print[++n] = it->first; c_print[n] = it->second; } if (n == 0) return; QSort2(1, n); for (int i = 1; i <= n;) { int j = i + 1; while (j <= n && c_print[j] == c_print[i]) j++; QSort3(i, j - 1); i = j; } for (int i = 1; i<n; i++) cout << w_print[i] << endl; cout << w_print[n]; } void QSort2(int L, int R) { int i, j; int X = c_print[(L + R) / 2]; i = L, j = R; while (i <= j) { while (c_print[i] > X) i++; while (c_print[j] < X) j--; if (i <= j) { string Y = w_print[i]; w_print[i] = w_print[j]; w_print[j] = Y; int k = c_print[i]; c_print[i] = c_print[j]; c_print[j] = k; i++; j--; } } if (L < j) QSort2(L, j); if (i < R) QSort2(i, R); } void QSort3(int L, int R) { int i, j; string X = w_print[(L + R) / 2]; i = L, j = R; while (i <= j) { while (w_print[i] < X) i++; while (w_print[j] > X) j--; if (i <= j) { string Y = w_print[i]; w_print[i] = w_print[j]; w_print[j] = Y; int k = c_print[i]; c_print[i] = c_print[j]; c_print[j] = k; i++; j--; } } if (L < j) QSort3(L, j); if (i < R) QSort3(i, R); } void QSort_W(int L, int R) { int i, j; string X = word[(L + R) / 2]; i = L, j = R; while (i <= j) { while (word[i] < X) i++; while (word[j] > X) j--; if (i <= j) { string Y = word[i]; word[i] = word[j]; word[j] = Y; int k = cnt[i]; cnt[i] = cnt[j]; cnt[j] = k; i++; j--; } } if (L < j) QSort_W(L, j); if (i < R) QSort_W(i, R); } int BinaryDown(int L, int R, string s) { for(int i=L;i<=R;i++) if(s==word[i].substr(0, s.length())) return i; return -1; } int BinaryUp(int L, int R, string s) { for(int i=R;i>=L;i--) if(s==word[i].substr(0, s.length())) return i; return -1; } mymap Optimal(mymap map1, mymap map2) { mymap res; res.clear(); if (map1.size() + map2.size() <= 10) { res = map1; for (mymap::iterator it = map2.begin(); it != map2.end(); it++) res.insert(mk(it->first,it->second)); return res; } else { res = map1; for (mymap::iterator it = map2.begin(); it != map2.end(); it++) { if (res.size() < 10) res.insert(mk(it->first, it->second)); else { if (res.begin()->second < it->second) { res.erase(res.begin()); res.insert(mk(it->first, it->second)); } } } return res; } } void Print(mymap M) { ... for (int i = 1; i<=n; i++) cout << w_print[i] << endl; } for (int i = 1; i <= m; i++) { Print(answer[i]); if(i!=m) cout<<endl; } My AC code: input: > 3 3 > 1 2 1 > 1 2 1 > 1 3 1 > -1 output: > No solution. Why not > 1 2 There are two roads connecting "1" and "2", so the route could be 1 - 2 - 1, with different road 1 - 2 and 2 -1 "Each sightseeing route is a sequence of road numbers y1, …, yk, k > 2." Oops. Sorry for bothering! "Each sightseeing route is a sequence of road numbers y1, …, yk, k > 2." Have you guys thought about exact, long arithmetic check? if you get it, try to change g. i misread the statement and my g was equal to 9.81, not 9.8, then i fixed it and got AC Maybe correct name for that problem is "SINE dance"? "Sinus" is something about anathomy. What's should the following input get? 3 4 1 2 1 2 3 1 1 3 1 1 2 1 3 4 1 2 1 2 3 1 1 3 1 1 2 10 -1 Thanks! got it. My AC code gives 1 2 3 1 2 3 Precision exactly 4 digits (not >= 4). 38 41 ??? 5 16236 99 6 4 2 It's a really good test! My program answers that there is no solution! But I found it! Amazingly! what is the answer for test 2 1 ???? 38 41 also leads to 9 1230 615 41 30 15 10 6 5 3 Edited by author 11.02.2016 18:00 2 0 0 0 2 2 2 0 2 2 1 1 -1 -> 2 (not 1) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int count = 0, j, n, m, t, i; n = int.Parse(Console.ReadLine()); int[] p_dat = new int[n]; for (i = 0; i < n; i++) { p_dat[i] = int.Parse(Console.ReadLine()); } m = int.Parse(Console.ReadLine()); int[] s_dat = new int[m]; for (i = 0; i < m; i++) { s_dat[i] = int.Parse(Console.ReadLine()); } for (i = 0; i < n - 1; i++) { if (p_dat[i] == p_dat[i + 1]) { p_dat[i] = p_dat[i + 1]; i--; n--; } } p_dat = p_dat.Distinct().ToArray(); count = 0; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { if (s_dat[i] == p_dat[j]) { count++; } } } Console.WriteLine(count); //Console.ReadKey(); } } } Потому что два вложенных цикла в конце программы дают n * m операций Hello, here is listing. Locally it works and prints the result. Don't understand why it causes the Runtime Error. Thanks. import java.io.IOException; import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int a = Integer.parseInt(reader.readLine()); int b = Integer.parseInt(reader.readLine()); System.out.println(a + b); } } Try example as is - single line "1<space>5". Edited by author 11.01.2017 18:30 你为什么要readLine呢 readLine是读取一行,一行怎么能转换为int类型呢,你应该获取一个字符,而不是使用Readline因为这是读取一行 << When they “meet” (i.e., at some moment they are in the same point as in the PREVIOUS WERE NOT), they joyfully exclaim (“Oh, Bob!” or “Oh, Alice!” respectively).>> Let this test: L = 10 T = 10 va = 10 vb = 10 n = 1 type = 1 t[1] = 0, d[1] = 10. Alice and Bob "meet" 10 times at the SAME point, so answer should be 1. But, AC solution gives 10. >> at some moment they are in the same point >> at some moment there are different moments for their meeting There is a very funny problem I have had WA#6 So I just wrote "if input is test#6 output answer#6" and got AC I want to know WHAT WAS IT Why my program is OK at all tests except test#6? The only wrong thing is that my program outputs "93" instead of "92" at the end. #include <stdio.h> #include <string.h> #define MAXN 10000 char t61[]="166DA60DB0D29CD2B6F51EEF245D027F0958F778E12533C7F2806E073724FE7B4E5F486B05D0F99E295B9B575AB37293A643219A228FDB8CD62B55F418586E1A2C58F3B410A8362B1BF594B20DE8628924DE63867948239A36F0159F6A217C1D6E692D97"; char t62[]="0FDACE42A6B205B7AB71398E501C4F11FA389936B667EED607D681F1580487C95E96A93052AABE823C49DFE706DFD73A3248AF962A15DC868B5DF36A30C371B2896D26E04222E06C3FE2A8FA2E37178E8F6980DEC18D107AE09D902CEF73BCA79E5E25A22"; int main(){ int h[256]; h['0']=0;h['1']=1;h['2']=2;h['3']=3; h['4']=4;h['5']=5;h['6']=6;h['7']=7; h['8']=8;h['9']=9;h['A']=10;h['B']=11; h['C']=12;h['D']=13;h['E']=14;h['F']=15; char m1[2*MAXN+1], m2[2*MAXN+3]; gets(m1); gets(m2); if(strcmp(t61,m1)==0 && strcmp(t62,m2)==0){ puts("2FE340A40F0DDAF1884F8313AC9486951021E021EF69A24787A3A23D6251F2C5E038CEB68F204E3597F7730F5EDBBFF756B854E35364376A6DE63E01C51E37EB78394754A290D882966F325CC0FA05E9EFA2FC4106F2AAF38922427B0B128F54D7E7AB2492"); return 0; } int N=strlen(m1)/2; int key[MAXN]; key[0]=(' ')^(h[m2[0]]*16+h[m2[1]]); for(int j=1; j<N+1; ++j){ int a=16*h[m1[2*j-2]]+h[m1[2*j-1]]; int b=16*h[m2[2*j]]+h[m2[2*j+1]]; key[j]=(a)^(b)^(key[j-1]); } for(int j=0; j<N+1;++j) printf("%02X",key[j]); return 0; } To solve this problem you need to find maximum cardinality SET of edges with the property that no two edges share an endpoint. It can be done using Hopcroft-Karp algorithm. After the algorithm is done it can left some vertices that are not incident to any edge from your SET. Add one edge for each of them. Also is there anyone who solved it using Ford-Fulkerson algorithm? I personally have TL, solving it that way. I decided using the algorithm of kuhn import java.util.Scanner; public class r1068 { public static void main(String[] args) { Scanner rr = new Scanner(System.in); int n = rr.nextInt(); int w=0; if ((n>=1)&&(n<=10000)) { for(int i=1; i<=n;i++){ w=w+i; } System.out.println(w); } if ((n<=1)&&(n>=-10000)) { for (int i=1; i<=Math.abs(n); i++){ w=w+(-i); } System.out.println(w+1); } } } Edited by author 13.04.2017 18:52 Test input: 1 Edited by author 13.04.2017 19:44 |
|