zoukankan      html  css  js  c++  java
  • [NOIP2004] 普及组

    不高兴的津津

    纯模拟

     1 #include<cmath>
     2 #include<cstdio>
     3 #include<iostream>
     4 using namespace std;
     5 int main(){
     6     int a[8],b,c,i,t;
     7     a[0]=8;
     8     t=0;
     9     for (i=1;i<=7;++i){
    10         a[i]=0;
    11         b,c=0;
    12         cin>>b;
    13         cin>>c;
    14         a[i]=b+c;
    15     }
    16     for (i=1;i<=7;++i)
    17         if (a[i]>a[t]) 
    18             t=i;
    19     printf("%d",t);
    20     return 0;
    21 }
    不高兴的津津

    花生采摘

    贪心模拟即可。

    刚开始理解错了题意,以为可以通过先回到路边再去摘其他花生来缩短时间,WA了几次

    花生采摘

    FBI树

    递归模拟

    FBI warning

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cmath>
     5 using namespace std;
     6 int n;
     7 char s[30];
     8 void solve(int l,int r){
     9     bool fb=0,fw=0;
    10     for(int i=l;i<=r;++i){
    11         if(s[i]=='0')fb=1;
    12         if(s[i]=='1')fw=1;
    13     }
    14     int mid=(l+r)>>1;
    15     if(l<r){
    16         solve(l,mid);
    17         solve(mid+1,r);
    18     }
    19     if(fb && fw)printf("F");
    20     if(fb && !fw)printf("B");
    21     if(!fb && fw)printf("I");
    22     return;
    23 }
    24 int main(){
    25     scanf("%d",&n);
    26     scanf("%s",s+1);
    27     int i,j;
    28     n=pow(2,n);
    29     solve(1,n);
    30     return 0;
    31 }
    FBI树

    火星人

    本来是一道很考思维的搜索,但是用了STL秒过……

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 using namespace std;
     5 int a[10000];
     6 int main()
     7 {
     8     int n,m;
     9     cin>>n>>m;
    10     for (int i=1;i<=n;i++) cin>>a[i];
    11     int cnt=0;
    12     while (cnt<m)
    13     {
    14         next_permutation(a+1,a+n+1);
    15         cnt++;
    16     }
    17     for(int i=1;i<=n;i++)printf("%d ",a[i]);
    18     return 0;
    19 }
    火星人
  • 相关阅读:
    HashMap按键排序和按值排序
    LeetCode 91. Decode Ways
    LeetCode 459. Repeated Substring Pattern
    JVM
    LeetCode 385. Mini Parse
    LeetCode 319. Bulb Switcher
    LeetCode 343. Integer Break
    LeetCode 397. Integer Replacement
    LeetCode 3. Longest Substring Without Repeating Characters
    linux-网络数据包抓取-tcpdump
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5991422.html
Copyright © 2011-2022 走看看