5 条题解
-
2莫言 (slz莫言) LV 10 @ 2024-11-27 13:03:02
#include <bits/stdc++.h> #define LL long long using namespace std; const int N = 100000 + 10; const int INF = 0x3f3f3f3f; int n , m , cnt , k; struct node { int id; int sum; }a [N]; bool cmp (node a1 , node a2) { if (a1.sum == a2.sum) return a1.id < a2.id; return a1.sum > a2.sum; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a [i].sum; a [i].id = i; } sort (a + 1 , a + n + 1 , cmp); for (int i = 1 ;i <= n; i++) { cout << a [i].id << " "; } cout << "\n"; for (int i = 1; i <= n; i++) { if (a [i].id == m) break; if(a [i - 1].sum != a [i].sum) { cnt += k; k = 1; } else k++; } cout << ++cnt; return 0; }
-
02024-11-28 22:05:05@
- #include<bits/stdc++.h> #include<algorithm> #include<iostream> #include<string.h> #include<stdio.h> #include<iomanip> #include<cstring> #include<math.h> #include<vector> #include<queue> #include<stack> #include<cstdio> #include<cmath> using namespace std; #define LL long long using namespace std; const int N = 100000 + 10; const int INF = 0x3f3f3f3f; int n , m , cnt , k; struct node { int id; int sum; }a [N];
bool cmp (node a1 , node a2) { if (a1.sum == a2.sum) return a1.id < a2.id; return a1.sum > a2.sum; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a [i].sum; a [i].id = i; } sort (a + 1 , a + n + 1 , cmp); for (int i = 1 ;i <= n; i++) { cout << a [i].id << " "; } cout << "\n"; for (int i = 1; i <= n; i++) { if (a [i].id == m) break; if(a [i - 1].sum != a [i].sum) { cnt += k; k = 1; } else k++; } cout << ++cnt; return 0; }
-
02024-11-28 22:04:48@
#include<bits/stdc++.h> #include<algorithm> #include<iostream> #include<string.h> #include<stdio.h> #include<iomanip> #include<cstring> #include<math.h> #include<vector> #include<queue> #include<stack> #include<cstdio> #include<cmath> using namespace std; #define LL long long using namespace std; const int N = 100000 + 10; const int INF = 0x3f3f3f3f; int n , m , cnt , k; struct node { int id; int sum; }a [N];
bool cmp (node a1 , node a2) { if (a1.sum == a2.sum) return a1.id < a2.id; return a1.sum > a2.sum; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a [i].sum; a [i].id = i; } sort (a + 1 , a + n + 1 , cmp); for (int i = 1 ;i <= n; i++) { cout << a [i].id << " "; } cout << "\n"; for (int i = 1; i <= n; i++) { if (a [i].id == m) break; if(a [i - 1].sum != a [i].sum) { cnt += k; k = 1; } else k++; } cout << ++cnt; return 0; }
-
02024-11-24 22:05:31@
报错的 别看
-
02024-11-24 22:04:43@
#include<bits/stdc++.h> #include<algorithm> #include<iostream> #include<string.h> #include<stdio.h> #include<iomanip> #include<cstring> #include<math.h> #include<vector> #include<queue> #include<stack> #include<cmath> using namespace std; #define LL long long using namespace std; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; int a[1001][5],n; void kp(int l,int r) { int t,x,i=l,j=r; x=a[(l+r)/2][3]; while(i<=j) { while(x>a[i][3])i++; while(x<a[j][3])j--; if(i<=j) { t=a[i][0];a[i][0]=a[j][0];a[j][0]=t; t=a[i][1];a[i][1]=a[j][1];a[j][1]=t; t=a[i][2];a[i][2]=a[j][2];a[j][2]=t; t=a[i][3];a[i][3]=a[j][3];a[j][3]=t; t=a[i][4];a[i][4]=a[j][4];a[j][4]=t; i++;j--; } } if(l<j)kp(l,j); if(i<r)kp(i,r); } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]); a[i][3]=a[i][0]+a[i][1]+a[i][2];a[i][4]=i; } kp(1,n); int t; for(int i=1;i<=n;i++) { int k=i; while(a[i][3]==a[k][3])k++; k--; for(int j=k;j>=i;j--) for(int m=j;m<k;m++) if(a[m][4]<a[m+1][4]) { t=a[m][0];a[m][0]=a[m+1][0];a[m+1][0]=t; t=a[m][1];a[m][1]=a[m+1][1];a[m+1][1]=t; t=a[m][2];a[m][2]=a[m+1][2];a[m+1][2]=t; t=a[m][3];a[m][3]=a[m+1][3];a[m+1][3]=t; t=a[m][4];a[m][4]=a[m+1][4];a[m+1][4]=t; } } for(int i=n;i>=1;i--) printf("%d %d %d %d\n",a[i][0],a[i][1],a[i][2],a[i][3]); return 0; }
- 1
信息
- ID
- 1966
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 326
- 已通过
- 35
- 上传者