Common Board using System; using System.Globalization; namespace a_b { public class Program { private static void Main() { int first = 0; int N = int.Parse(Console.ReadLine()); if (N <= System.Math.Abs(1000)) { if (N == 1) { first = 1; for (int i = 1; i <= N; i++) { first += i; } } if (N > 1) { first = 0; for (int i = 0; i <= N; i++) { first += i; } } if (N < 1) { first = 1; for (int i = 0; i >= N; i--) first += i; } Console.WriteLine(first); } } } } 0 and 1 is trivial solution. Let x solution it must satisfy for follow requirements: {x=0(mod p);x=1(mod q);} or {x=0(mod q);x=1(mod p);} We can find 2 solution for these equation let it be x1,x2; And all solution will satisyf for follow requirements (x1+lcm(p,q))mod n,(x2+lcm(p,q))mod n; but lcm(p,q)==n we have only for solutions 0 1 x1 x2; Sorry for bad English! who can give some tests like test 4, pls. test 4 is first big test n>90000. And another hint with probability. Calculate p[s]=1-p[s]/100. and p[t]=1-p[t]/100. and use the simple algo BFS . Try to calculate the best probability by formula p[qu->nod]=p[min] * qu->cost; where qu->nod the current node, and qu->cost the probability of this node. Dont forget that the answer is 1.-p[t]. The time of this algo is not good - 0,359, but it is very simple. Good luck!! P.S.qu->cost the same as p[s] and p[t] must be recalculate at the begining like this fscanf(in, "%d %d %d", &x, &y, &z); a[x]=new graf(y,1.-z/100.,a[x]); Sorry for my english!! Edited by author 04.06.2013 13:48 I am having problem in 1. Plz tell me that what should i do to solve this? Can you give me a hint with test #41? С хера он не принимает задачу?! Вот: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Dimmell { class Program { static void Main(string[] args) { int a = Convert.ToInt32(Console.ReadLine()); int b = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(a + b); } } } Edited by author 03.06.2013 19:24 Ok, so my program gets WA2. And if I add code like int t2=45; if(n==2) cout << t2 << endl; I get WA3. Funny fact though - "45" is answer my program always gave for n==2. So we have two different "45", and only one of them is good as answer. Somehow cout << s(9,n) << endl; doesn't work well, even if s(9,n)=45. Someone had problems of this kind? Ok-key, my bad. Had some good little out-of-array code in my check function, so it spoiled everything. I'm getting a 'runtime error: access violation' on my code. Please help me out. Here is the program in C++: #include<iostream> using namespace std; int main() { int i,j,a,sum,p,q; float small,ratio[30],x; cin>>p>>q; //Inputs //To find the ratio for each number in the interval i to j. for(i=p;i<=q;i++) {sum=0; for(j=1;j<i;j+=1) { if(i%j==0) { sum+=j; } } ratio[i]=sum/i; } //To find the number with the smallest ratio and display it. small=ratio[p]; for(i=p+1;i<=q;i+=1) { if(ratio[i]<small) { small=ratio[i]; x=i; } } cout<<x; return 0; } Please explain the test, I think there 're something wrong or I don't understand the task. I've read that problem twice, but i didn't undestand Sample is Correct, You misunderstanding the prob, we didn't add the number's together, we "bit or" the number Notice that the Branches ID is 1, 2, 4, 8, 16 ~~ and so on So if this cross road has a Number 5 it means 1001(in Binary), so it has 2 branches : type 1 and type 3 we must output the total sum of branch types, so when we meet two cross road with 5 and 1,we must use operation 'bit or' (in C, it's '|') to calculate the total sum of branch types. so you understand? Edited by author 27.08.2008 20:51 The obscurity of the statement is outrageous! For each point you need to increase distances until you find a distance, such that there are some non-zeros or you reach the distance of 5. Once you reach the distance you need to bitwise OR all the numbers at this distance. Thanks, this is helping. but its very difficult to get this point of stopping at distance when one gets or of values greater than zero. As I can see this statement is wrong: "Пиксели нумеруются от левого верхнего угла, по диагоналям, слева-направо и снизу-вверх". There should be "сверху-вниз". Am I right? No, you are not right. See one more time: 1 3 6 2 5 8 4 7 9 :) Edited by author 01.06.2013 22:05 Edited by author 02.05.2011 23:00 There is a method that you can find the solution with one loop. here is a hint: 1. if solution is s and sn is the number of s, then 2 * sn > n 2. if you delete any two different numbers until there is no different number, so this number is s.(because 2 * sn > n). And you can do deleting with one loop. good luck Thanks use quickSort and output [n/2] value... what is test case 7? I think my doing well. #include<stdio.h> int main() { int n,val[1001],pos1=2,pos2=1,sum[1001]; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&val[i]); for(int i=2;i<=n-1;i++) { sum[i]=val[i-1]+val[i]+val[i+1]; } for(int i=2;i<=n-1;i++) { if(sum[i]>=sum[i+1]) { sum[i+1]=sum[i]; pos2++; } else if(sum[i]<sum[i+1]) { pos1+=pos2; pos2=1; } } printf("%d %d",sum[n-1],pos1); } I don't understand where I'm wrong. I tried the sample and the result is right! #include<iostream> #include<map> using namespace std; int main() { int n,num; map<char,int> val; val['a']=1;val['b']=2;val['c']=3;val['d']=3;val['e']=3;val['f']=3;val['g']=2;val['h']=1; val['1']=1;val['2']=2;val['3']=3;val['4']=3;val['5']=3;val['6']=3;val['7']=2;val['8']=1; char xy[1]; cin>>n; while(n--) { cin>>xy; num=val[xy[0]]+val[xy[1]]; if(num==6) num+=2; if(num==5) num++; cout <<num<<endl; } } import java.util.*; public class Penguins1585 { /** * @param args */ public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = Integer.parseInt(in.nextLine()); int a=0,b=0,c=0; for(int i=0; i<n; i++){ String s = in.nextLine(); String s1=s.substring(0,1); if(s1.equals("E"))a++; else if(s1.equals("M"))b++; else c++; }
if(a>=b && a>=c)System.out.print("Emperor Penguin"); else if(b>=a && b>=c) System.out.print("Macaroni Penguin"); else System.out.print("Little Penguin");
} } The question is simple. So is my code. See below It gets AC in VC++2000. But why does it get WA#1 in gcc4.7.2 and gcc4.7.2-c++11, until I replace the while-scanf loop with the commented while-cin loop? Thanks. -- #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <vector> int main() { std::vector<long long> v; long long t; while (std::scanf("%lld", &t) != EOF) { // while (std::cin >> t) { v.push_back(t); } for (int i=v.size()-1; i>=0; --i) { printf("%.5f\n", sqrt((double)(v[i]))); } } In this test use LONG INT. I use INT and got WA, but later I use LONG INT and got AC. #include <stdio.h> #include <math.h> #define N 4 int main() { long double a[N]; long double b[N]; int i = 0; while(i < N) { scanf("%Lf",&a[i]); b[i]=sqrt((long double)a[i]); i++; } if(i == N) for(i= N - 1; i>=0; i--) { printf("%.4Lf\n", b[i]); }
} seems to return the right values. But writes "Wrong answer". Thanks! |
|