标签:include code for 输入 ret poj2182 sys 树状数组 amp
说好的树状数组+二分,说好的线段树
你却暴力过了
可恶(O^O)#!
题意:有1~n个奶牛,编号为1~n乱序排列,现在给定第2~n个奶牛,它们前面有多少只牛的编号比自己小
样例:
输入:5 1 2 1 0
输出: 2 4 5 3 1
逆推,第n个前面有0个比自己小的,则第n个编号为1
考虑1 1 1 1 1------前缀和
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int N = 5e5 + 100; 6 int a[N], c[N],ans[N]; 7 int main(){ 8 int n; 9 cin >> n; 10 a[1] = 0; 11 c[1] = 1; 12 for (int i = 2; i <= n;i++){ 13 scanf("%d", &a[i]); 14 c[i] = 1; 15 } 16 ans[n] = a[n] + 1; 17 c[ans[n]] = 0; 18 for (int i = n-1; i >= 1;i--){ 19 int num = 0; 20 for (int j = 1; j <= n;j++){ 21 num += c[j]; 22 if(num==a[i]+1){ 23 ans[i] = j; 24 c[j] = 0; 25 break; 26 } 27 } 28 } 29 for (int i = 1; i <= n;i++){ 30 printf("%d\n", ans[i]); 31 } 32 //system("pause"); 33 return 0; 34 }
标签:include code for 输入 ret poj2182 sys 树状数组 amp
原文地址:https://www.cnblogs.com/guaguastandup/p/10628372.html