• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Hug_Sea
博客园    首页    新随笔    联系   管理    订阅  订阅

2680 Problem F: Coin Game

题意:给出两个序列a[],b[],第一个递减,第二个随机,问怎样交换第二个序列(每次相邻两个互换),使得第二个序列每个位置上的数都小于等于第一个序列。

例:sample input:

3
3 2 1
2 2 1
3
3 2 1
1 2 3
4
6 5 3 1
1 3 5 5

sample output:

0

3

5

思路:a,b都从最后开始遍历,若a[i]<b[i],则将b[i]移到a[i]后面,否则标记b[i]。

 

View Code
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <string>
 5 #include <algorithm>
 6 #include <iostream>
 7 using namespace std;
 8 const int N=110;
 9 
10 int a[N],b[N];
11 
12 int main(){
13     
14 //    freopen("data.in","r",stdin);
15 //    freopen("data.out","w",stdout);
16     
17     int n,i,j;
18     while(scanf("%d",&n)!=EOF){
19         for(i=1;i<=n;i++) cin>>a[i];
20         for(i=1;i<=n;i++) cin>>b[i];
21         int ans=0;
22         for(i=n;i>=1;i--){
23             for(j=n;j>=1;j--){
24                 if(a[i]<b[j]) ans++;
25                 else if(b[j]!=-1){b[j]=-1; break;}
26             }
27         }
28         cout<<ans<<endl;
29     }
30     return 0;
31 }
posted @ 2012-05-09 15:49  Hug_Sea  阅读(119)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3