1, Unique minimum
Title Link
Given an integer array a1,a2,..., an of length n.
Please find the smallest number in the array that only appears once.
Output the index number of the number found.
The index number of a1 is 1, the index number of a2 is 2,..., and the index number of an is n.
Input format
The first row contains the integer T, indicating that there are t groups of test data.
The first row of each set of data contains the integer n.
The second line contains n integers a1,a2,..., an.
Output format
Each group of data outputs a row of results, that is, the index number of the number that meets the conditions. If there is no number that meets the conditions, it outputs − 1.
Data range
1≤T≤2×104,
1≤n≤2×105,
1≤ai≤n,
The sum of all n in the same test point shall not exceed 2 × 105.
Input example:
6
2
1 1
3
2 1 3
4
2 2 2 3
1
1
5
2 3 2 4 2
6
1 1 5 5 4 4
Output example:
-1
2
4
1
2
-1
Traverse again, record the number of occurrences of this element, record the number of occurrences of 1, and then sort.
memset is in bytes, each int plus 4 bytes
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<vector> using namespace std; const int N=200010; int w[N],cnt[N]; int main() { int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); memset(cnt,0,(n+1)*4);//It's not necessary for every element to come once for(int i=0;i<n;i++) { scanf("%d",&w[i]); cnt[w[i]]++; } int res=-1; for(int i=0;i<n;i++)//hash if(cnt[w[i]]==1) { if(res==-1||w[res]>w[i]) res=i; } if(res!=-1) res++; printf("%d\n",res); } return 0; }
Tool, which is created to solve data analysis tasks.
2, Binary matrix
Title Link
Given an n × m-Size binary matrix, which contains only 0 and 1.
Now, you can do the following: select a 2 × 2, and change the values of three elements (0 becomes 1 and 1 becomes 0).
Your task is to change all elements in the matrix to 0 through the above operation.
Your total number of operations should not exceed 3nm times.
It can be proved that the answer must exist.
Input format
The first row contains the integer T, indicating that there are t groups of test data.
The first row of each set of data contains integers n,m.
The next n lines, each containing a 01 string of length m, represent a given binary matrix.
Output format
The first row of each group of data outputs the integer k, which represents the number of operations. Pay attention to the weight range of K [0,3nm].
The next k lines contain 6 integers x1, Y1, X2, Y2, X3 and Y3. The coordinates describing the selected elements in an operation are (x1,y1), (x2,y2), (X3 and Y3).
The element position cannot be the same and must come from the same 2 × 2 in the submatrix.
The rows and columns are counted from 1, (1,1) represents the elements in the upper left corner of the input matrix, (n,m) represents the elements in the lower right corner of the input matrix.
Any reasonable scheme can be output.
Data range
1≤t≤5000,
2≤n,m≤100,
Ensure that the nm of each group of data in the same test point must not exceed 20000.
Input example:
5
2 2
10
11
3 3
011
101
110
4 4
1111
0110
0110
1111
5 5
01011
11001
00010
11011
10000
2 3
011
101
Output example:
1
1 1 2 1 2 2
2
2 1 3 1 3 2
1 2 1 3 2 3
4
1 1 1 2 2 2
1 3 1 4 2 3
3 2 4 1 4 2
3 3 4 3 4 4
4
1 2 2 1 2 2
1 4 1 5 2 5
4 1 4 2 5 1
4 4 4 5 3 4
2
1 3 2 2 2 3
1 2 2 1 2 2
It's a bit like looking for rules. If you change a grid (the last row and the last column need special judgment) three times, he will change his value
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<vector> using namespace std; const int N=110; int n,m; char g[N][N]; void pL(int i,int j,int k) { if(!k)printf("%d %d %d %d %d %d\n",i,j,i+1,j,i,j+1); else if(k==1)printf("%d %d %d %d %d %d\n",i,j-1,i,j,i+1,j); else if(k==2)printf("%d %d %d %d %d %d\n",i-1,j,i,j,i,j-1); else printf("%d %d %d %d %d %d\n",i-1,j,i,j,i,j+1); } int main() { int T; scanf("%d",&T); while(T--) { cin>>n>>m; int res=0; for(int i=1;i<=n;i++) { cin>>g[i]+1;//Read directly from row [i] [1] for(int j=1;j<=m;j++) if(g[i][j]=='1') res+=3; } cout<<res<<endl; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(g[i][j]=='1') { if(i<n&&j<m) pL(i,j,0),pL(i,j+1,1),pL(i+1,j,3); else if(i==n&&j==m) pL(i,j,2),pL(i-1,j,1),pL(i,j-1,3); else if(i==n) pL(i,j,3),pL(i-1,j,0),pL(i,j+1,2); else pL(i,j,1),pL(i,j-1,0),pL(i+1,j,2); } } return 0; }