喵哈哈村的魔法考试 Round #3 (Div.2)

菜的抠脚

A

题解:判断能否构成一个三角形。

#include "iostream"
#include "algorithm"
#include "cmath"
using namespace std;
int main(){
  int T,a[3];
  cin>>T;
    while(T--){
    for(int i=0;i<3;i++)  cin>>a[i];
    sort(a,a+3);
    if((a[0]+a[1]>a[2]) && (abs(a[0]-a[1])<a[2] )){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}

B

题解:开始走T/length(order),然后再走T%length(order)

#include "iostream"
#include "algorithm"
#include "cstring"
using namespace std;

char s[5000+10];
int t,len;

void Walk(int &x,int &y,char s){
  if(s=='E') x++;
  else if(s=='W') x--;
  else if(s=='N') y++;
  else if(s=='S') y--;
}
int main(int argc, char const *argv[]) {
  /* code */
  int x,y;
  x = y = 0;
  while(std::cin >> s>> t){
    int len = strlen(s);
    for(int i=0;i<len;i++){
      Walk(x,y,s[i]);
    }
    x = x*( t/len );  y = y*( t/len );
    t %= len;
    for(int i=0;i<t;i++)  Walk(x,y,s[i]);
    std::cout << x <<" "<< y << '
';
    x = y = 0;
  }
  return 0;
}

C

题解: 我也不清楚为什么要用随机数做。。。 因为qsc oj是并行系统,所以。。。。 初始化随机数种子srand(time(NULL))是错的,可以用C++ new申请新空间,新申请的空间地址是随机的,所以以随机地址作为随机数种子。因为随机嘛,总有脸黑的时候。。。

// 正常想法是随机,感觉上来说随机几次就能AC。但是随机种子,决定了你的随机数。
// Srand(time(NULL))是不行的,因为这个OJ采用的是并发测评的模式,所以你获取的TIME(null)种子是一样的。
// 这儿一个正确做法是,抓取定义字符的内存,这个内存地址是随机的,然后来随机就好了
#include "stdio.h"
#include "time.h"
#include "stdlib.h"
#include "iostream"
using namespace std;

// new的用法:
// 1. Elemtype * = new Elemtype
// 2. Elemtype * = new Elemtype( init )  以圆括号中数值进行初始化
// 3. Elemtype * = new Elemtype [ number ] 开辟一个number大小的空间,开辟二维空间相类似
// delete的用法和new用法相对应,销毁时不需要初始化
int main(){
  int *a=new int[5];
  srand((unsigned long) a);
  delete[] a;
  printf("%d
",(rand()&1)+1);
  return 0;
}

D

题解:直接暴力所有可能,用到了海伦公式S=sqrt(p * (p-a) * (p-b) * (p-c)) p=(a+b+c)/2,没看到保留整数......g

#include "iostream"
#include "algorithm"
#include "cmath"
#include "cstdio"
using namespace std;

int main() {
  /* code */
  int n;
  double num[200];
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> num[i];
    }
    // 数据小,暴力所有可能
    sort(num,num+n);
    double p,s,M_s = -1;
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
        for(int k=j+1;k<n;k++)
          if( num[i]+num[j]>num[k] )
          {
            p = (num[i]+num[j]+num[k])/2.0;
            s = sqrt(p*(p-num[i])*(p-num[j])*(p-num[k]));
            M_s = max(s,M_s);
          }
    if( M_s==-1 )  std::cout << "-1" << '
';
    else  printf("%.0lf
", s);
  }
  return 0;
}

E

题解:直接查日历......

#include "iostream"
#include "algorithm"
#include "cstdio"
#include "string"
using namespace std;

int main(){
  int t;
  char str[1000];
  // 注意星期5 6 是53天
  int week[8]={0,52,52,52,52,53,53,52}; ?
  int month[32];
  for(int i=1;i<=31;i++){
    if(i==30) month[i]=11;
    else if(i==31) month[i]=7;
    else month[i]=12;
  }
  while(cin>>t){
    gets(str);
    if(str[4]=='w') printf("%d
",week[t]);
    else printf("%d
",month[t]);
  }
  return 0;
}
如要转载请注明转载出处:http://www.cnblogs.com/WArobot
原文地址:https://www.cnblogs.com/WArobot/p/6497526.html