Codeforces Beta Round #4 (Div. 2 Only)

点击打开链接

A

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
   int n;
   while(scanf("%d" , &n) != EOF){
      if(n < 4)
        printf("NO\n");
      else{
        if(n%2 == 0)
          printf("YES\n");
        else
          printf("NO\n");
      }
   }

   return 0;
}

B

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

#define MAXN 35

int d , sumTime;
int minTime[MAXN] , maxTime[MAXN];

int main(){
   int tmpMin , tmpMax;
   while(scanf("%d%d" , &d , &sumTime) != EOF){
      tmpMin = tmpMax = 0;
      for(int i = 0 ; i < d ; i++){
         scanf("%d%d" , &minTime[i] , &maxTime[i]);
         tmpMin += minTime[i];
         tmpMax += maxTime[i];
      }
      if(tmpMin > sumTime || sumTime > tmpMax)
         printf("NO\n");
      else{
         int mark = 0;
         printf("YES\n");
         for(int i = 0 ; i < d ; i++){
            if(tmpMin != sumTime){
               int count = minTime[i];
               for(int j = minTime[i]+1 ; j <= maxTime[i] ; j++){
                  if(tmpMin == sumTime)
                    break;
                  count++;
                  tmpMin++;
               }
               if(!mark){
                 printf("%d" , count);
                 mark = 1;
               }
               else
                 printf(" %d" , count);
            }
            else{
              if(!mark){
                printf("%d" , minTime[i]);
                mark = 1;
              }
              else
                printf(" %d" , minTime[i]);
            }
         }
      }
   }
   return 0;
}

C

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define MAXN 100010
#define N 40

int n , pos;
char ch[MAXN][N];
int vis[MAXN];

int main(){
  char name[N];
  while(scanf("%d" , &n) != EOF){
      memset(vis , 0 , sizeof(vis));
      pos = 0;

      int mark , cnt , p;
      for(int i = 0 ; i < n ; i++){
         scanf("%s" , name);
         mark = 1;
         for(int j = 0 ; j < pos ; j++){
            if(strcmp(ch[j] , name) == 0){
              mark = 0;
              cnt = vis[j]++;
              p = j;
              break;
            }
         }
         if(mark){
           printf("OK\n");
           strcpy(ch[pos] , name);
           vis[pos++]++;
         }
         else
           printf("%s%d\n" , ch[p] , cnt);
      }
  }
  return 0;
}

D

/*
思路:dp+路径输出
分析:
1 题目要求的是找到最多的信封的个数并输出编号,如果没有则输出0
2 很明显额矩形嵌套问题,利用dp求解,路径输出利用回溯法记录前驱点。

代码:
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define MAXN 5010

int n , w , h;
int pos , ans , mark;
int pre[MAXN];
int dp[MAXN];
struct envelop{
   int w;
   int h;
   int number;
}e[MAXN];

/*排序*/
bool cmp(envelop e1 , envelop e2){
   if(e1.w != e2.w)
     return e1.w < e2.w;
   return e1.h < e2.h;
}

/*事先判断有没有满足的信封*/
bool judge(){
   for(int i = 0 ; i < n ; i++){
      if(e[i].w > w && e[i].h > h){
        pos = i;
        return true;
      }
   }
   return false;
}

/*回溯法输出*/
void output(int x){
  if(pre[x] == x){
     printf("%d" , e[x].number);
     return;
  }
  output(pre[x]);
  printf(" %d" , e[x].number);
}

void solve(){

   ans = 0;
   for(int i = pos ; i < n ; i++){
      dp[i] = 1;
      pre[i] = i;
      for(int j = pos ; j < i ; j++){
         if(e[j].w > w && e[j].h > h && e[i].w > e[j].w && e[i].h > e[j].h && dp[j]+1 > dp[i]){
            dp[i] = dp[j] + 1;
            pre[i] = j;
         }
      }
      if(ans < dp[i]){
        ans = dp[i];
        mark = i;
      }
   }
   printf("%d\n" , ans);
   output(mark);
   printf("\n");
}

int main(){
   while(scanf("%d%d%d" , &n , &w , &h) != EOF){
      for(int i = 0 ; i < n ; i++){
         scanf("%d%d" , &e[i].w , &e[i].h);
         e[i].number = i+1;
      }
      sort(e , e+n , cmp);
      if(!judge())
        printf("0\n");
      else
        solve();
   }
   return 0;
}
时间: 2024-10-24 22:27:30

Codeforces Beta Round #4 (Div. 2 Only)的相关文章

Codeforces Beta Round #9 (Div. 2 Only)

点击打开链接cf#9 A 思路:求gcd然后化简 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int gcd(int a ,int b){ return b == 0 ? a : gcd(b , a%b); } int main(){ int a , b; while(scanf("%d%d"

Codeforces Beta Round #12 (Div 2 Only)

点击打开链接 A #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; char str[3][3]; bool isOk(){ for(int i = 0 ; i < 3 ; i++){ for(int j = 0 ; j < 3 ; j++){ if(str[i][j] != str[2-i][2-j]) r

Codeforces Beta Round #6 (Div. 2 Only)

点击打开链接 A #include<iostream> #include<cstdio> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; int l[4]; int main(){ while(scanf("%d%d%d%d" , &l[0] , &l[1] , &l[2] , &l[3])

Codeforces Beta Round #10

点击打开链接cf#10 A 思路:模拟 分析: 1 题目要求找到总共的电脑的消耗.题目明确指出在n个时间段之内电脑都是属于第一种状态,并且如果不是第一种状态只要移动鼠标或按键盘马上变为第一种状态. 2 题目还指出每一组输入都保证L<R,并且Ri-1<Li.那么我们只要每输入一个就处理一个即可. 代码: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm>

Codeforces Beta Round #11

点击打开链接 A #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int MAXN = 2010; int n , d; int num[MAXN]; int main(){ while(scanf("%d%d" , &n , &d) != EOF){ for(int i

Codeforces Beta Round #8

点击打开链接 A 思路:正反字符串各自判断一次是否有对应的两个子串 分析: 1 题目给定一个字符串str,然后给定两个不同时间段内看到的子串s1 , s2,判断是哪一种情况. 2 我们知道两个时间段内那么看到的字符串是有间隔的,那么如果我们怎么知道是否是"向前""向后""都有""没有"这四种答案中的哪一种呢?其实我们知道如果给定的两个子串都是给定的字符串str的子串,那么我们就必须正反都判断是否都能按照顺序看到s1 和 s2.

Codeforces Beta Round #3

点击打开链接 A #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<map> using namespace std; #define MAXN 500010 #define N 10 int ans , end; int sx , sy , ex , ey; int vis[N][N]; int dir[8][2] = {{0,1

Codeforces Beta Round #7

点击打开链接 A #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define N 8 char G[N][N]; int main(){ while(scanf("%s" , G[0]) != EOF){ for(int i = 1 ; i < 8 ; i++) scanf("%

Codeforces Beta Round #1

点击打开链接 A #include<iostream> #include<cstdio> using namespace std; long long n , m , a; int main(){ long long sum; while(cin>>n>>m>>a){ long long x , y; x = n%a == 0 ? n/a : n/a+1; y = m%a == 0 ? m/a : m/a+1; sum = x*y; cout&l