You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printfinstead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input().
The first line contains a non-negative integer a.
The second line contains a non-negative integer b.
The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits.
Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=".
9 10
<
11 10
>
00012345 12345
=
0123 9
>
0123 111
>
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int maxm=1e6+20; char s1[maxm]; char s2[maxm]; int a1[maxm]; int a2[maxm]; int main() { while(scanf("%s%s",s1,s2)!=EOF) { int cnt=0,cmt=0; int ind=strlen(s1)-1,inm=strlen(s2)-1; for(int i=0; i<strlen(s1); i++) { if(s1[i]=='0') { continue; } else { ind=i; break; } } for(int i=0; i<strlen(s2); i++) { if(s2[i]=='0') { continue; } else { inm=i; break; } } for(int i=ind; i<strlen(s1); i++) { a1[cnt++]=(s1[i]-'0'); } for(int i=inm; i<strlen(s2); i++) { a2[cmt++]=(s2[i]-'0'); } if(cnt>cmt) { printf(">\n"); } else if(cnt<cmt) { printf("<\n"); } else { int ok=0; for(int i=0; i<cnt; i++) { if(a1[i]>a2[i]) { ok=1; printf(">\n"); break; } else if(a1[i]<a2[i]) { ok=1; printf("<\n"); break; } else { continue; } } if(!ok) { printf("=\n"); } } } return 0; }
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Print the only integer a — the cost of the dinner for Jack and Emma.
3 4 4 1 3 5 2 2 2 2 5 4 5 1
2
3 3 1 2 3 2 3 1 3 1 2
1
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define LL long long const LL maxm=1e3+10; const LL inf=1e9+10; LL c[maxm][maxm]; int main() { LL m,n; while(scanf("%lld%lld",&m,&n)!=EOF) { for(LL i=0; i<m; i++) { for(LL j=0; j<n; j++) { scanf("%lld",&c[i][j]); } } LL Max=0; for(LL i=0; i<m; i++) { LL M=inf; for(LL j=0; j<n; j++) { M=min(M,c[i][j]); } Max=max(M,Max); } printf("%lld\n",Max); } return 0; }
You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side.
Let's call a connected component any non-extendible set of cells such that any two of them are connected by the path of adjacent cells. It is a typical well-known definition of a connected component.
For each impassable cell (x, y) imagine that it is an empty cell (all other cells remain unchanged) and find the size (the number of cells) of the connected component which contains (x, y). You should do it for each impassable cell independently.
The answer should be printed as a matrix with n rows and m columns. The j-th symbol of the i-th row should be "." if the cell is empty at the start. Otherwise the j-th symbol of the i-th row should contain the only digit —- the answer modulo 10. The matrix should be printed without any spaces.
To make your output faster it is recommended to build the output as an array of n strings having length m and print it as a sequence of lines. It will be much faster than writing character-by-character.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printfinstead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The first line contains two integers n, m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the field.
Each of the next n lines contains m symbols: "." for empty cells, "*" for impassable cells.
Print the answer as a matrix as described above. See the examples to precise the format of the output.
3 3 *.* .*. *.*
3.3 .5. 3.3
4 5 **..* ..*** .*.*. *.*.*
46..3 ..732 .6.4. 5.4.3
In first example, if we imagine that the central cell is empty then it will be included to component of size 5 (cross). If any of the corner cell will be empty then it will be included to component of size 3 (corner).
#include<stdio.h> #include<string.h> #include<string> #include<iostream> #include<set> #include<algorithm> using namespace std; const int maxm=1e3+10; char s[maxm][maxm]; char s1[maxm][maxm]; int vis[maxm][maxm]; int VIS[maxm][maxm]; int w[maxm][maxm]; int a[maxm][maxm]; int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}}; int m,n; int cur; int num; set<int>q; void dfs(int x,int y) { vis[x][y]=1; num++; for(int i=0; i<4; i++) { int xx=x+dir[i][0]; int yy=y+dir[i][1]; if(xx>=0&&xx<m&&yy>=0&&yy<n&&!vis[xx][yy]&&s[xx][yy]=='.') { dfs(xx,yy); } } } void DFS(int x,int y) { w[x][y]=cur; a[x][y]=num; VIS[x][y]=1; for(int i=0; i<4; i++) { int xx=x+dir[i][0]; int yy=y+dir[i][1]; if(xx>=0&&xx<m&&yy>=0&&yy<n&&!VIS[xx][yy]&&s[xx][yy]=='.') { DFS(xx,yy); } } } int main() { while(scanf("%d%d",&m,&n)!=EOF) { memset(vis,0,sizeof(vis)); memset(VIS,0,sizeof(VIS)); memset(w,0,sizeof(w)); memset(a,0,sizeof(a)); cur=0; num=0; for(int i=0; i<m; i++) { scanf("%s",s[i]); } for(int i=0; i<m; i++) { for(int j=0; j<n; j++) { if(s[i][j]=='.') { num=0; if(!vis[i][j]) { dfs(i,j); cur++; DFS(i,j); } } } } for(int i=0; i<m; i++) { for(int j=0; j<n; j++) { if(s[i][j]=='.') { s1[i][j]='.'; } else { q.clear(); int sum=0; for(int k=0; k<4; k++) { int xx=i+dir[k][0]; int yy=j+dir[k][1]; if(xx>=0&&xx<m&&yy>=0&&yy<n&&s[xx][yy]=='.'&&q.find(w[xx][yy])==q.end()) { sum+=a[xx][yy]; q.insert(w[xx][yy]); } } s1[i][j]='0'+((sum+1)%10); } } } for(int i=0; i<m; i++) { printf("%s\n",s1[i]); } } return 0; }
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printfinstead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The first line contains two integers n, k (1 ≤ k ≤ n ≤ 5·105) — the number of elements in a and the parameter k.
The second line contains n integers ai (0 ≤ ai ≤ 106) — the elements of the array a.
Print two integers l, r (1 ≤ l ≤ r ≤ n) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
5 5 1 2 3 4 5
1 5
9 3 6 5 1 2 3 2 1 4 5
3 7
3 1 1 2 3
1 1
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int maxm=1e6+10; int a[maxm]; int vis[maxm]; int main() { int n,k; while(scanf("%d%d",&n,&k)!=EOF) { memset(vis,0,sizeof(vis)); int count=0; int L=0,R=0; int l=0,r=0; int Max=0; for(int i=0; i<n; i++) { scanf("%d",&a[i]); } for(int i=0; i<n; i++) { if(!vis[a[i]]) { count++; } vis[a[i]]++; while(count>k) { vis[a[l]]--; if(!vis[a[l]]) { count--; } l++; } if(i-l+1>Max) { Max=i-l+1; L=l; R=i; } } printf("%d %d\n",L+1,R+1); } return 0; }