3 条题解

  • 1
    @ 2022-6-12 10:17:10
    #include<bits/stdc++.h>
    using namespace  std;
    const int mx=610;
    int c[mx];//x分的人有多少个
    int n,w,ans,cnt,x,i;
    
    int  main()
    {
    	for(int i=0; i<=600; i++) c[i]=0;
    	cin>>n>>w;
    	for (int i=1; i<=n; i++)
    		{
    			cin>>x;
    			c[x]++;
    			cnt=floor(i*w/100);
    			cnt=max(cnt,1);
    			ans=600;
    			int s=c[ans];
    			while (s<cnt)
    				{
    					ans--;
    					s+=c[ans];
    				}
    			cout<<ans<<' ';
    		}
    	return 0;
    }
    
    • 0
      @ 2022-9-3 20:14:04

      主要运用计数排序的思想,但是开了三层数组用于优化常数

      #include <iostream>
      
      int main() {
      
          std::ios::sync_with_stdio(false);
          int n, w;
          std::cin >> n >> w;
      
          static int score1[601];
          static int score2[80];
          static int score3[10];
      
          int tmp, plan_people, i, j1, j2, j3;
          auto get_plan_people = [w](int i) -> int {
              int t = (i + 1) * w / 100;
              return t > 1 ? t : 1;
          };
      
          for (i = 0; i < n; ++i) {
              std::cin >> tmp;
              ++score1[tmp];
              ++score2[tmp >> 3];
              ++score3[tmp >> 6];
              plan_people = get_plan_people(i);
              for (j1 = 9; j1 >= 0; --j1) {
                  if (plan_people > score3[j1]) {
                      plan_people -= score3[j1];
                  } else {
                      break;
                  }
              }
              j1 <<= 3;
              for (j2 = 7; j2 >= 0; --j2) {
                  if (plan_people > score2[j1 + j2]) {
                      plan_people -= score2[j1 + j2];
                  } else {
                      break;
                  }
              }
              j2 = (j1 + j2) << 3;
              for (j3 = 7; j3 >= 0; --j3) {
                  if (plan_people > score1[j2 + j3]) {
                      plan_people -= score1[j2 + j3];
                  } else {
                      break;
                  }
              }
              j3 = j2 + j3;
              std::cout << j3 << ' ';
          }
          std::cout << std::endl;
      
          return 0;
      }
      
      • 0
        @ 2022-3-27 21:20:03

        比较容易能想到桶排序。每次输入就从1到600去扫一遍。

        #include<bits/stdc++.h>
        using namespace std;
        int bac[605],n,w,x;
        int main() {
        	cin>>n>>w;
        	for(int i=1;i<=n;i++) {
        		cin>>x;
        		bac[x]++;
        		int sum=0;
        		for(int j=600;j>=0;j--) {
        			sum+=bac[j];
        			if(sum>=max(1,i*w/100)) {
        				cout<<j<<" ";
        				break;
        			}
        		}
        	}
        	return 0;
        } 
        
        • 1

        信息

        ID
        122
        时间
        1000ms
        内存
        256MiB
        难度
        2
        标签
        递交数
        58
        已通过
        38
        上传者