2 条题解
-
0李诺一 (linuoyi2) LV 5 @ 2024-9-17 15:28:52
/* int %o/%lo(八进制) %d/%i/%ld/%li(十进制) %x/%lx(十六进制)[如标名为o/lo/d/i/lo/li/x/lx即输出为八进制/十进制/十六进制] longlong %lld float %f/%e double %lf/%le char %c char[] %s 'a'=97 'z'=122 'A'=65 'Z'=90 '0'=48 '9'=57 */ #include <iostream> #include <iomanip> #include <cmath> #include <cstdio> #include <cstring> #include <algorithm> #include <ctime> #include <limits> #include <assert.h> #include <stdlib.h> using namespace std; #define LL long long #define ull unsigned long long const int N=1e5+10; const int INF=0x3f3f3f3f; const double pi=3.1416; int n,m,ans; struct sb{ int x; int id; }a[N]; bool cmp(sb a1,sb a2){ return a1.x<a2.x; } int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i].x; a[i].id=i; } cin>>m; sort(a+1,a+n+1,cmp); for(int i=1;i<=n;i++){ cout<<a[i].x<<" "; if(a[i].x==m){ ans=a[i].id; } } cout<<endl; if(ans){ cout<<ans; }else{ cout<<"Not Find"; } return 0; }
-
-12022-9-24 16:07:27@
#include <iostream> #include <algorithm> using namespace std; int n, x; struct node { int num,id; }a[1000010]; int find(int num) { int l = 0, r = n-1; while (l <= r) { int mid = (l + r) / 2; if (num == a[mid].num) return a[mid].id; else if (num < a[mid].num) r = mid - 1; else l = mid + 1; } return -1; } bool cmp(node x, node y) { return x.num < y.num; } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].num; a[i].id = i+1; } sort (a, a + n,cmp); cin >> x; for (int i = 0; i < n; i++) { cout << a[i].num << " "; } cout << endl; int findnum = find(x); if(findnum == -1) cout << "Not Find"; else cout << findnum << endl; }
- 1
信息
- ID
- 1564
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 427
- 已通过
- 122
- 上传者