Common Boardplease tell me how 1 1 2 2 can be YES.Because if Nick take cards for example that 0 1 reads 1 1 2 reads 1 2 3 reads 2 and he can't write 1 2 and 2 3 and answer must be NO i think Sorry I understnd all :) Edited by author 17.08.2008 04:31 Edited by author 17.08.2008 04:32 i don't understand why it can be YES Edited by author 22.04.2014 12:25 #include <cstdio> #include <climits> #include <cstdlib> #include <algorithm> #include <list> #include <vector> using namespace std; #define PB push_back #define BEG begin() #define MP make_pair #define F first #define S second bool compare(const pair<int,int> &left, const pair<int,int> &right){ return left.F <= right.F; } int main(){ int M; int readInt1, readInt2; vector<pair<int,int> > segments; vector<int> solutionInd; scanf("%d", &M); while(scanf("%d %d", &readInt1, &readInt2) && !(readInt1 == 0 && readInt2 == 0)){ segments.PB(MP(readInt1, readInt2)); } sort(segments.begin(), segments.end(), compare); if(segments.empty() || segments[0].F > 0){ printf("No solution\n"); return 0; }
int currEnd = 0; int segInd = 0; int ansInd = -1; int maxEnd = 0;
while(segInd < segments.size()){ while(segInd < segments.size() && segments[segInd].F <= currEnd){ if(segments[segInd].S > maxEnd){ maxEnd = segments[segInd].S; ansInd = segInd; }
segInd++; } solutionInd.PB(ansInd); currEnd = maxEnd;
if(currEnd >= M || segments[segInd].F > currEnd) break; } if(solutionInd.empty() || currEnd < M){ printf("No solution\n"); } else{ printf("%d \n", solutionInd.size()); for(int i = 0; i<solutionInd.size(); i++){ printf("%d %d\n", segments[solutionInd[i]].F, segments[solutionInd[i]].S); } }
}
Keep getting runtime error(Access violation) even though I can't find anywhere it is possible to go outside the vectors memory space.
Update: The problem was accepted when using visual studio compiler instead of g++. Same thing happened to me. But why is that? Hi, I get WA6 with g++ but get runtime error access violation on test case 14 with Visual Studio 2010 C++. Code : /* * File: main.cpp * Author: Parnami * Created on April 14, 2014, 10:18 PM * Description : TIMUS Online Judge Problem ID : 1303 (DP) */ #include <stdio.h> #include <iostream> #include <algorithm> #include <vector> #include <map> #include <string> #include <queue> #include <cmath> #include <utility> #include <limits.h> using namespace std; inline int fastRead() { int input; char c=0; while (c<33) c=getchar(); input=0; while (c>33) { input=input*10+c-'0'; c=getchar(); } return input; } vector < pair <int,int> > myVec,answer; bool inRange(pair <int,int> cur, int starter) { if(starter>=cur.first && starter<cur.second) return true; return false; } int main(int argc, char** argv) { int m,starter,ender,iter,i,flag; pair <int,int> maxxer,current; m = fastRead(); while(1) { cin>>starter>>ender; if(starter==0&&ender==0) break; if(ender<=0||(starter>=m&&ender>m)) { //Do Nothing } else { //cout<<"Pushing "<<starter<<"-"<<ender<<endl; myVec.push_back(make_pair(starter,ender)); } } if(!myVec.empty()) { sort(myVec.begin(),myVec.end()); iter = 0; starter=0; while(starter<m) { //cout<<starter<<endl; current = myVec[iter]; //cout<<"Yahaan Phuncha"<<endl; flag = 0; while(!inRange(current,starter) && iter!=myVec.size()) { //cout<<"Not in range : "<<current.first<<"-"<<current.second<<endl; iter++; current = myVec[iter]; } if(iter==myVec.size()) { //cout<<"End of vector nowhere to search"<<endl; flag = 1; break; } maxxer = current; iter++; if(iter==myVec.size()) {
} else { while(1) { if(myVec[iter].first>starter) { break; } else { if(myVec[iter].second>maxxer.second) { maxxer = myVec[iter]; } iter++; } } } //cout<<"Pushing into answer "<<maxxer.first<<"-"<<maxxer.second<<endl; answer.push_back(maxxer); starter = maxxer.second; } } else flag=1; if(flag) { cout<<"No solution"<<endl; } else { cout<<answer.size()<<endl; for(i=0;i<answer.size();i++) { cout<<answer[i].first<<" "<<answer[i].second<<endl; } } return 0; } Edited by author 15.04.2014 04:19 #include <iostream> #include <iomanip> #include <math.h> using namespace std; int main() { long double a[100000]; int i = -1; while (cin >> a[++i]); while (i > 0) cout << fixed << setprecision(4) << sqrt(a[--i]) << endl; return 0; } Here is my code, what's the problem? #include <algorithm> #include <iostream> #include <vector> #include <sstream> #include <string> #include <cstdlib> #include <cstdio> #include <iomanip> using namespace std; int main(){ int count[26]; int max = 0; char answer = '-'; for (char p = 'a'; p < char('z') + 1; p++) { count[p] = 0; } char c; while (cin.get(c)) { count[c]++; } for (char p = 'a'; p < char('z') + 1; p++) { if (count[p] > max){ max = count[p]; answer = p; } } cout << answer; } Help please)! Why WA 1? I check my Pascal code and the answer is right! Maybe, it means that test 1 not look like sample My codes solves all the samples from all Topics but i always get wrong answer #1. If I'm not mistaken, test 1 is the first sample. Do you have the right output format? It´s only an integer, so what to Format? It´s a C# program, i tested Console.WriteLine and also Console.Write. I have absolutely no idea what to. import java.util.Scanner; public class main { public static void main(String args[]) throws Exception { Scanner s = new Scanner(System.in); int v = Integer.parseInt(s.nextLine()); int c = Integer.parseInt(s.nextLine()); if (c != 0 || v != 0) { System.out.print(c - 1 + " "); System.out.print(v - 1); } else { System.out.println("Error"); } } } v chom oshibka import java.io.*; import java.text.DecimalFormat; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); List<Double> a = new ArrayList<Double>(); while (in.hasNextDouble() ) { a.add(in.nextDouble()); } DecimalFormat df = new DecimalFormat("#.0000"); for (int i = a.size() - 1; i >= 0; --i) { out.println(df.format(Math.sqrt(a.get(i)))); } } } As described in the subject. 3 1 0 0 0 1 0 0 9 0 0 -1 0 0 5 0 0 -1 0 0 -------------- ALARM! 2.000 1 3 I think the actual solution may like this: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int harry, larry, max;
while(sc.hasNext()){ harry = sc.nextInt(); larry = sc.nextInt();
max = harry + larry;
if(((max % 10) != 0)){
if(((max % 10) <= ((max / 10)))){ max = (10 * ((max / 10))); } else{ max = (10 * ((max / 10) + 1)); } } System.out.println((max - harry) +" "+ (max - larry)); } sc.close(); } } Try this: 4 1 2 2 3 2 10 1 1 10 4 1 0 Edited by author 22.11.2006 03:43 Thank you a lot! Thank you. It helped me too! I tried building solution by taking two matrices dpA[i][j] which tells me the count including the carriages from 1 to i of length k ending at A. Similarly I constructed dpB[i][j] (somewhat similar to 0-1 knapsack). But of course this is wrong as my output will depend on the ordering of the carriages in input. Any suggestions if this approach can be corrected or need to think in completely different direction? Thanks! I have "Time limit exceeded" in test #12. But time of work is 0.234. Max time in test conditionы is 2.0. I think it is mistake in data reading. Maybe program waits reading data from test. do { var operation = Console.Read(); var request = Console.ReadLine(); ... } while (Console.In.Peek() != -1); Edited by author 12.04.2014 18:28 Edited by author 12.04.2014 18:28 After getting several WA on test1, I realized that I was counting the wrong position. In order to get AC, we should read the sequence from LEFT TO RIGHT. For example, for '11101', the first position is 1, second is 1, third is 1 and the final should be 1. After I reading the sequence from left to right, I finally got AC. My C++ solution: #include <iostream> using namespace std; struct team { int id; int n; }; int main() { register int temp, temp_2; team *com; team temp_team; int i; cin >> i; com = new team[i]; for ( temp = 0; temp < i; temp++ ) { cin >> com[temp].id >> com[temp].n; } for ( temp = 0; temp < i; temp++ ) for ( temp_2 = 0; temp_2 < i; temp_2++ ) { if ( com[temp].n > com[temp_2].n ) { temp_com = com[temp]; com[temp] = com[temp_2]; com[temp_2] = temp_com; } } for ( temp = 0; temp < i; temp++ ) { cout << com[temp].id << " " << com[temp].n << endl; } return 0; } My code #include <stdio.h> int main() { long long n, s; int m; scanf("%lld%d",&n,&m); n*=(long long)3; s=0; for(int i=0; i<m; i++) { int t; scanf("%d",&t); s+=t; if(s>n) { printf("Free after %d times.",i+1); return 0; } } printf("Team.GOV!"); return 0; } Works fine on my machine under Linux (g++ 4.8.2). On the OnlineJudge I get WA1 on g++ and AC on VC++ 2010. I think something is wrong. %lld doesn't work for MinGW GCC. Use %I64d In Pascal I have AC, but in Java - WA, why?? /* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out);
int N, M, Y = 0; boolean check = false;
N = in.nextShort(); M = in.nextShort(); Y = in.nextShort();
double p;
if ( ((0<N) && (N<999)) && ((1<M) && (M<999)) && ((0<Y) && (Y<999)) ) { for (int X=0; X<=M-1; ++X) { p = ((Math.pow(X,N)) % M); if (p == Y) { if (X != (M-2)) { out.print(X + " "); } else { out.print(X); } check = true; } } }
if (!check) { out.print("-1"); }
out.flush(); } } A couple of tests that I obtained from my working program: 998 999 972 48 63 159 174 270 285 381 396 492 507 603 618 714 729 825 840 936 951 998 999 900 -1 Scroll down for hint. v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v Hint: (A*B) MOD C = ((A MOD C) * B) MOD C Edited by author 13.10.2011 19:15 Edited by author 13.10.2011 19:16 With numbers 998 999 972 answer must be -1< because, 1 < M < 999 Code link: REMOVED after ac I can't provide a test though but the bug that was causing WA was simple. My DP recurrence was simple, dp[s][e] contains the shortest folding for the segment a[s]a[s+1]...a[e], where 'a' is the main string. Now, then I was calculating dp[s][e] I made an error and dp[s][e] was in some rare cases containing solutions of dp[s][e+1]dp[s][e+2]... ans the resulting sequence was containing lower length then actually possible. Edited by author 19.08.2013 11:15 Edited by author 19.08.2013 15:43 aaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaab aaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaab aaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaab aaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaab aaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaab aaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaab aaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaabaaaaaaaaab |
|