菜的抠脚

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 << '\n';
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\n",(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" << '\n';
else printf("%.0lf\n", 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\n",week[t]);
else printf("%d\n",month[t]);
}
return 0;
}

最新文章

  1. DOM 事件深入浅出(二)
  2. Windows Phone 执行模型概述
  3. PostgreSQL数据库服务端监听设置及客户端连接方法教程
  4. (转)JSON数据格式和js操作json总结
  5. Labview实现单边带信号调制(SSB)[滤波法]
  6. 使用canvas制作在线画板
  7. HTML5 简单画图,切片,变形
  8. 玩转Web之servlet(一)---怎样创建一个servlet
  9. IntelliJ IDEA环境配置
  10. 如何在当前目录下快速打开cmd(或者以管理员的身份打开)
  11. 2018-2019-2 《网络对抗技术》Exp0 Kali安装
  12. Luogu3579 Solar Panels
  13. Django-rest-framework 接口实现 权限:(Permission)
  14. Leading and Trailing(巧妙利用log解决次方问题)
  15. IP首部格式[转载]
  16. 【LeetCode】27. Remove Element (2 solutions)
  17. 经典实用的iptables shell脚本
  18. pip 18.1 官方文档翻译
  19. Angular material mat-icon 资源参考_Device
  20. 05_dubbo_aop

热门文章

  1. 修改Xorg.conf配置显示分辨率
  2. [Linux]Apache配置虚拟主机
  3. Objective-C学习笔记(二十二)——初始化方法init的重写与自己定义
  4. 什么是鸭子类型(duck typing)
  5. NUnit Console Command Line
  6. (Go)02.go 安装delve调试工具测试
  7. 最详细的CentOS 6与7对比(二):服务管理对比
  8. mysql 强制修改密码
  9. Chrome 行情抓取插件
  10. git window端工具之sourcetree使用