poj-1017-Packets

呂振麒 bio photo By 呂振麒 Comment

傳送門

Packets

code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <cstring>
using namespace std;
int cnt[10], ans;
bool get_data(){
  ans = 0;
  memset(cnt, 0, sizeof(cnt));
  for(int i=1;i<=6;i++)
    scanf("%d", cnt+i);
  for(int i=1;i<7;i++)if(cnt[i])
    return true;
  return false;
}
int main(){
  while(get_data()){
    ans+=(cnt[6]+cnt[5]+cnt[4]+(cnt[3]>>2));
    cnt[1] -= (cnt[5]*11);
    cnt[2] -= (cnt[4]*5);
    cnt[3] %= 4;
    if(cnt[3]>0){
      ans++;
      cnt[2]-=(7-(cnt[3]<<1));
      cnt[1]-=(8-cnt[3]);
    }
    if(cnt[2]>0){
      ans+=(cnt[2]/9);
      cnt[2]%=9;
      if(cnt[2]){
        ans++;
        cnt[1]-=(36-(cnt[2]<<2));
      }
    }
    else if(cnt[2]<0){
      cnt[2] *= -1;
      cnt[1]-=(cnt[2]<<2);
    }
    if(cnt[1]>0){
      ans+=(cnt[1]/36 + (cnt[1]%36?1:0));
    }
    printf("%d\n", ans);
  }
}
    /*
    switch(cnt[3]){
      case 1:
        cnt[2]-=5;
        cnt[1]-=7;
        break;
      case 2:
        cnt[2]-=3;
        cnt[1]-=6;
        break;
      case 3:
        cnt[2]-=1;
        cnt[1]-=5;
    }*/
comments powered by Disqus