2013年5月11日 zoj比赛三道水题:zoj4998 Break Standard Weight && zoj5004 Hard to Play && zoj5006 Java Beans

May 11, 2013
zoj

都是水题,特别水的内种,题目意思、思路神马滴就不说了……   Break Standard Weight 题目链接:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=4998 范围只有100,并且只有3个数字,直接枚举,代码好挫……o(╯□╰)o 只有一个需要注意的地方,就是绝对值为0的时候要考虑到!因为如果绝对值为0,那么根本就称不出什么重量来。。


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
typedef long long int LL;
const int MAXN =  0x7fffffff;
const int  MINN =  -0x7fffffff;
const double eps = 1e-9;
const int dir[8][2] = {{0,1},{1,0},{0,-1},{-1,0},{-1,1},
  {1,1},{1,-1},{-1,-1}};
map<int, bool>mymap; 
int main(void){
#ifndef ONLINE_JUDGE
  freopen("zoj4998.in", "r", stdin);
#endif
  int t, x, y, max, sum, i, j, k, a, b, c;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &x, &y);
    max = 0;
    for (i = 1; i < x/2; ++i) {
      a = i; b = x - i; c= y;
      sum = 0;
      mymap.clear();
      mymap[a] = true; sum++;
      if (!mymap[b]) {mymap[b] = true;sum++;}
      if (!mymap[c]) {mymap[c] = true;sum++;}

      if (!mymap[abs(a+b)]) {mymap[abs(a+b)] = true;sum++;}
      if (!mymap[abs(a+b-c)] && a+b-c!=0) {mymap[abs(a+b-c)] = true;sum++;}
      if (!mymap[abs(a+b+c)]) {mymap[abs(a+b+c)] = true;sum++;}

      if (!mymap[abs(a-b)] && a-b!=0) {mymap[abs(a-b)] = true;sum++;}
      if (!mymap[abs(a-b+c)] &&a-b+c!=0) {mymap[abs(a-b+c)] = true;sum++;}
      if (!mymap[abs(a-b-c)]&&a-b-c!=0) {mymap[abs(a-b-c)] = true;sum++;}

      if (!mymap[abs(c+b)]) {mymap[abs(c+b)] = true;sum++;}
      if (!mymap[abs(c+b-a)]&&c+b-a!=0) {mymap[abs(c+b-a)] = true;sum++;}

      if (!mymap[abs(c-b)] &&c!=b) {mymap[abs(c-b)] = true;sum++;}
      if (!mymap[abs(c-b+a)]&&c-b+a!=0) {mymap[abs(c-b+a)] = true;sum++;}
      if (!mymap[abs(c-b-a)]&&c-b-a!=0) {mymap[abs(c-b-a)] = true;sum++;}

      if (!mymap[abs(a+c)]) {mymap[abs(a+c)] = true;sum++;}
      if (!mymap[abs(a+c-b)]&&a+c-b!=0) {mymap[abs(a+c-b)] = true;sum++;}

      if (!mymap[abs(a-c)]&&a-c!=0) {mymap[abs(a-c)] = true;sum++;}
      if (sum > max) max = sum;
    }
    for (i = 1; i < y; ++i) {
      a = i; b = y - i; c= x;
      sum = 0;
      mymap.clear();
      mymap[a] = true; sum++;
      if (!mymap[b]) {mymap[b] = true;sum++;}
      if (!mymap[c]) {mymap[c] = true;sum++;}

      if (!mymap[abs(a+b)]) {mymap[abs(a+b)] = true;sum++;}
      if (!mymap[abs(a+b-c)] && a+b-c!=0) {mymap[abs(a+b-c)] = true;sum++;}
      if (!mymap[abs(a+b+c)]) {mymap[abs(a+b+c)] = true;sum++;}

      if (!mymap[abs(a-b)] && a-b!=0) {mymap[abs(a-b)] = true;sum++;}
      if (!mymap[abs(a-b+c)] &&a-b+c!=0) {mymap[abs(a-b+c)] = true;sum++;}
      if (!mymap[abs(a-b-c)]&&a-b-c!=0) {mymap[abs(a-b-c)] = true;sum++;}

      if (!mymap[abs(c+b)]) {mymap[abs(c+b)] = true;sum++;}
      if (!mymap[abs(c+b-a)]&&c+b-a!=0) {mymap[abs(c+b-a)] = true;sum++;}

      if (!mymap[abs(c-b)] &&c!=b) {mymap[abs(c-b)] = true;sum++;}
      if (!mymap[abs(c-b+a)]&&c-b+a!=0) {mymap[abs(c-b+a)] = true;sum++;}
      if (!mymap[abs(c-b-a)]&&c-b-a!=0) {mymap[abs(c-b-a)] = true;sum++;}

      if (!mymap[abs(a+c)]) {mymap[abs(a+c)] = true;sum++;}
      if (!mymap[abs(a+c-b)]&&a+c-b!=0) {mymap[abs(a+c-b)] = true;sum++;}

      if (!mymap[abs(a-c)]&&a-c!=0) {mymap[abs(a-c)] = true;sum++;}
      if (sum > max) max = sum;
    }
    printf("%d\n", max);
  }

  return 0;
}

就是有个困惑,写这样的代码,如果没有vim,日子该怎么过…… 还是把上面的代码修改一下吧,用mymap.size(),依然还是得去掉0的情况。看来自己STL还是需要好好学习啊!不然搞的那么繁琐。。o(╯□╰)o  


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
typedef long long int LL;
const int MAXN =  0x7fffffff;
const int  MINN =  -0x7fffffff;
const double eps = 1e-9;
const int dir[8][2] = {{0,1},{1,0},{0,-1},{-1,0},{-1,1},
  {1,1},{1,-1},{-1,-1}};
map<int, bool>mymap; 
int main(void){
#ifndef ONLINE_JUDGE
  freopen("zoj4998.in", "r", stdin);
#endif
  int t, x, y, max, sum, i, j, k, a, b, c;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &x, &y);
    max = 0;
    for (i = 1; i < x/2; ++i) {
      a = i; b = x - i; c= y;
      mymap.clear();
      mymap[a] = mymap[b] = mymap[c] = true;
      mymap[abs(a+b)] = mymap[abs(a+b-c)] = mymap[abs(a+b+c)] = true;
      mymap[abs(a-b)] = mymap[abs(a-b+c)] = mymap[abs(a-b-c)] = true;
      mymap[abs(c+b)] = mymap[abs(c+b-a)] = true;
      mymap[abs(c-b)] = mymap[abs(c-b+a)] = mymap[abs(c-b-a)] = true;
      mymap[abs(c+a)] = true;
      mymap[abs(c-a)] = true;
      sum = mymap.size();
      if (mymap[0]) sum--; 
      if (max < sum) max = sum;
    }
    for (i = 1; i < y; ++i) {
      a = i; b = y - i; c= x;
      mymap.clear();
      mymap[a] = mymap[b] = mymap[c] = true;
      mymap[abs(a+b)] = mymap[abs(a+b-c)] = mymap[abs(a+b+c)] = true;
      mymap[abs(a-b)] = mymap[abs(a-b+c)] = mymap[abs(a-b-c)] = true;
      mymap[abs(c+b)] = mymap[abs(c+b-a)] = true;
      mymap[abs(c-b)] = mymap[abs(c-b+a)] = mymap[abs(c-b-a)] = true;
      mymap[abs(c+a)] = true;
      mymap[abs(c-a)] = true;
      sum = mymap.size();
      if (mymap[0]) sum--; 
      if (max < sum) max = sum;
    }
    printf("%d\n", max);
  }

  return 0;
}

  谢谢speedcell~     Hard to Play 题目链接:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5004 水题,也木有什么可以总结的。


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
typedef long long int LL;
const int MAXN =  0x7fffffff;
const int  MINN =  -0x7fffffff;
const double eps = 1e-9;
const int dir[8][2] = {{0,1},{1,0},{0,-1},{-1,0},{-1,1},
  {1,1},{1,-1},{-1,-1}};

int main(void){
#ifndef ONLINE_JUDGE
  freopen("zoj5004.in", "r", stdin);
#endif
  int t, i, sum, Max, Min, a, b, c, j, cnt;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d", &a, &b, &c);
    Max = Min = 0; cnt = 0; sum = 0;
    for (i = 0; i < a; ++i) {sum += (300*(cnt*2+1));cnt++;}
    for (i = 0; i < b; ++i) {sum += (100*(cnt*2+1));cnt++;}
    for (i = 0; i < c; ++i) {sum += (50*(cnt*2+1));cnt++;}
    Min = sum; sum = 0; cnt = 0;
    for (i = 0; i < c; ++i) {sum += (50*(cnt*2+1)); cnt++;}
    for (i = 0; i < b; ++i) {sum += (100*(cnt*2+1)); cnt++;}
    for (i = 0; i < a; ++i) {sum += (300*(cnt*2+1)); cnt++;}
    Max = sum;
    printf("%d %d\n", Min, Max);
  }

  return 0;
}

就是枚举一下,o(╯□╰)o   Java Beans 题目链接:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5006 注意到范围只有200,就是暴力……o(╯□╰)o


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
typedef long long int LL;
const int MAXN =  0x7fffffff;
const int  MINN =  -0x7fffffff;
const double eps = 1e-9;
const int dir[8][2] = {{0,1},{1,0},{0,-1},{-1,0},{-1,1},
  {1,1},{1,-1},{-1,-1}};
int a[220];
int main(void){
#ifndef ONLINE_JUDGE
  freopen("zoj5006.in", "r", stdin);
#endif
  int t; scanf("%d", &t);
  int n, m, i, j, k, sum, max;
  while (t--) {
    scanf("%d%d", &n, &m); max = -1;
    for (i = 0; i < n; ++i) scanf("%d", a + i);
    for (i = 0; i < n; ++i) {
      sum = 0;
      for (j = i; j < i + m; ++j) {
        sum += a[j%n];
      }
      if (max < sum) max = sum;
    }
    printf("%d\n", max);
  }

  return 0;
}

  好吧……这比赛就过了这三道水题,赶脚没什么收获,因为本来就没有用心做,态度都不端正,就想着试着做做就行了,结果什么收获都没有,以后,不管什么比赛,都要认真对待,否则就不要做!做水题真的木有意思,虽然这三道都是1A的,可是,那又有什么意义呢?不会的题目还是不会,会的题目还是会的,还不是原地踏步么?   为了让这次比赛有点儿意义,这次要把剩下的题目切掉!

comments powered by Disqus