暴力求解法/模拟

POJ2182 LOST COWS

说好的树状数组+二分,说好的线段树

你却暴力过了

可恶(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 }

 

 

CF sushi for two

有个人好可怜的,她这题FST了............

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define int long long
 4 #define re register
 5 #define sys system("pause");
 6 inline int read(){
 7     re int x=0,f=1;char c=getchar();
 8     while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
 9     while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
10     return x*f;
11 }
12 int a[100010],dp[100010],j,num,ans=1,cnt,n;
13 int32_t main(){
14     n = read();
15     for (int i = 1; i <= n;i++)
16         a[i] = read();
17     for (int i = 1; i <= n;i++){
18         cnt++;
19         dp[cnt] = 1;
20         for ( j =i ; j<= n;j++){
21             if(a[j]!=a[j+1]){
22                 dp[cnt] = j - i + 1;
23                 i = j;
24                 break;
25             }     
26         }
27     }
28     for (int i = 1; i <= cnt-1; i++){
29         num = min(dp[i], dp[i + 1]);
30         ans = max(num, ans);
31     }
32     cout << ans * 2;
33     sys
34     return 0;
35 }

“不能去想,越想就越轻。。。” 

 

CF BerSU Ball

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int a[105], b[105],ans,pos;
 4 int main(){
 5     int n, m;
 6     cin >> n; 7     for (int i = 0; i < n;i++)
 7         cin >> a[i];
 8       cin>>m;
 9     for (int i = 0; i < m;i++)
10         cin >> b[i];
11     sort(a, a + n);
12     sort(b, b + m);
13     for (int i = 0; i < n;i++){
14         for (int j = pos; j < m;j++){
15             if(a[i]-b[j]<=1&&a[i]-b[j]>=-1){
16                 ans++;
17                 pos = j + 1;
18                 break;
19             }
20         }
21     }
22     cout << ans;
23     return 0;
24 }

 

CF A prison transfer

 

求方法数,仍然是模拟题

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define int long long
 4 const int N = 2e5 + 100;
 5 int a[N];
 6 int n, t, c,cnt,ans;
 7 int32_t main(){
 8     cin >> n >> t >> c;
 9     for (int i = 0; i < n;i++)
10         cin >> a[i];
11 
12     for (int i = 0; i < n;i++){
13         if(a[i]>t){
14             if(cnt>=c)
15                 ans += (cnt - c + 1);
16             cnt = 0;
17         }
18         else
19             cnt++;
20     }
21     if(cnt>=c)//最后一次!!要处理!!
22         ans += (cnt - c + 1);
23     cout << ans;
24     //system("pause");
25     return 0;
26 }

 

转载于:https://www.cnblogs.com/guaguastandup/p/10628372.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值