Java面向对象2(G~J)
G 织女的红线(SDUT 2240)
import java.util.Scanner;
import java.text.DecimalFormat;
class Sum {
double x1, y1, x2, y2;
Sum(double n1, double m1, double n2, double m2) {
x1 = n1;
x2 = n2;
y1 = m1;
y2 = m2;
}
double getAns() {
double ans = 0;
ans = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
ans = Math.sqrt(ans);
return ans;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
DecimalFormat df = new DecimalFormat(".00");
int t, r;
double ans = 0;
double x[] = new double[200];
double y[] = new double[200];
t = sc.nextInt();
r = sc.nextInt();
for (int i = 1; i <= t; i++) {
x[i] = sc.nextDouble();
y[i] = sc.nextDouble();
}
x[t + 1] = x[1];
y[t + 1] = y[1];
Sum p;
for (int i = 1; i <= t; i++) {
p = new Sum(x[i], y[i], x[i + 1], y[i + 1]);
ans += p.getAns();
}
ans += 2 * r * 3.1415926;
System.out.println(df.format(ans));
}
}
H 分数加减法(SDUT 2253)
import java.util.Scanner;
import java.text.DecimalFormat;
class Sum {
int x1, y1, x2, y2;
char str;
Sum(int n1, int m1, int n2, int m2, char op) {
x1 = n1;
x2 = n2;
y1 = m1;
y2 = m2;
str = op;
}
int getGcd(int a, int b) {
int n = a, m = b;
while (m > 0) {
int x = n;
n = m;
m = x % m;
}
return n;
}
void getAns() {
int x = getGcd(y1, y2);
int a, b, c, d, ans1, ans2;
a = x1;
b = y1;
c = x2;
d = y2;
int lcm = b * d / x;
a = a * d / x;
c = c * b / x;
if (str == '+')
ans1 = a + c;
else
ans1 = a - c;
ans2 = lcm;
if (ans1 < 0)
x = -ans1;
else
x = ans1;
x = getGcd(x, ans2);
if (ans1 % x == 0 && ans2 % x == 0) {
ans1 /= x;
ans2 /= x;
}
if (ans1 == 0 && ans1 != ans2 || ans2 == 1)
System.out.println(ans1);
else if (ans1 == ans2)
System.out.println(1);
else
System.out.println(ans1 + "/" + ans2);
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// DecimalFormat df = new DecimalFormat(".00");
Sum p;
String s;
char op;
while (sc.hasNext()) {
s = sc.next();
// System.out.println(s);
int x1 = s.charAt(0) - '0';
int y1 = s.charAt(2) - '0';
op = s.charAt(3);
int x2 = s.charAt(4) - '0';
int y2 = s.charAt(6) - '0';
// System.out.println(x1 + " " + y1 + " " + x2 + " " + y2 + " " + op);
p = new Sum(x1, y1, x2, y2, op);
p.getAns();
}
}
}
高中数学?(SDUT 2400)
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
Sum p = new Sum(n);
int ans = p.getAns(n);
System.out.println(ans);
}
sc.close();
}
}
class Sum {
int a[] = new int[55];
int n;
public Sum(int n) {
a[1] = 0;
a[2] = 1;
for (int i = 3; i <= 50; i++) {
a[i] = 4 * a[i - 1] - 5 * a[i - 2];
}
this.n = n;
}
public int getAns(int n) {
return a[n];
}
}
最大矩形面积(SDUT 2401)
import java.lang.reflect.Array;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int n,l,w;
node s[] = new node[2000];
for (int i = 0; i < t; i++) {
l = sc.nextInt();
w = sc.nextInt();
n = sc.nextInt();
for(int j = 0; j < n; j ++)
{
s[j] = new node();
s[j].x = sc.nextInt();
s[j].y = sc.nextInt();
}
//Arrays.sort(s,0,n,new cmp());
Sum p = new Sum(l,w,n,s);
if(n == 0)
System.out.println(l * w);
else
System.out.println(p.getAns());
}
sc.close();
}
}
class node
{
int x;
int y;
}
class cmp implements Comparator<node>
{
public int compare(node a, node b)
{
if(a.x - b.x != 0) return a.x - b.x;
else return a.y - b.y;
}
}
class cmp1 implements Comparator<node>
{
public int compare(node a, node b)
{
if(a.y - b.y != 0) return a.y - b.y;
else return a.x - b.x;
}
}
class Sum {
int l,w,n;
node s[] = new node[2000];
Sum(int l, int w, int n, node s[])
{
this.l = l;
this.w = w;
this.n = n;
this.s = s;
}
int max(int a, int b)
{
if(a >= b) return a;
else return b;
}
int min(int a, int b)
{
if(a >= b) return b;
else return a;
}
int getAns1()
{
Arrays.sort(s,0,n,new cmp1());
int i,j,ans1;
ans1 = 0;
for (i = 0; i < n; ++i)
{
int L = 0, R = l;
for (j = i + 1; j < n; ++j)
{
if (s[i].y != s[j].y)
{
ans1 = max(ans1,(s[j].y - s[i].y)*(R - L));
if (s[j].x > s[i].x) R = min(R,s[j].x);
else L = max(L,s[j].x);
}
}
}
return ans1;
}
int getAns2()
{
Arrays.sort(s,0,n,new cmp());
int i,j,ans2;
ans2 = 0;
for (i = 0; i < n; ++i)
{
int top = w, down = 0;
for (j = i + 1; j < n; ++j)
{
if (s[i].x != s[j].x)
{
ans2 = max(ans2,(s[j].x - s[i].x)*(top - down));
if (s[j].y > s[i].y) top = min(top,s[j].y);
else down = max(down,s[j].y);
}
}
}
return ans2;
}
int getAns()
{
int ans,ans1,ans2;
ans1 = getAns1();
ans2 = getAns2();
ans = max(ans1,ans2);
return ans;
}
}
Java面向对象2(G~J)的更多相关文章
- java 面向对象 2
一.JAVA类的定义 JAVA里面有class关键字定义一个类,后面加上自定义的类名即可.如这里定义的person类,使用class person定义了一个person类,然后在person这个类的类 ...
- 【重走Android之路】【Java面向对象基础(三)】面向对象思想
[重走Android之路][基础篇(三)][Java面向对象基础]面向对象思想 1 面向对象的WWH 1.1 What--什么是面向对象 首先,要理解“对象”.在Thinkin ...
- 3. Java面向对象之泛型-指定多个泛型
3. Java面向对象之泛型-指定多个泛型 package generic; class MutiGeneric<K, T> { private K key; private T take ...
- 20175221曾祥杰 实验二《Java面向对象程序设计》
实验二<Java面向对象程序设计> 实验报告封面 课程:Java程序设计 班级:1752班 姓名:曾祥杰 学号:20175221 指导教师:娄嘉鹏 实验日期:2019年4月17日 实验时间 ...
- 20175209 实验二《Java面向对象程序设计》实验报告
20175209 实验二<Java面向对象程序设计>实验报告 一.实验前期准备 了解三种代码 伪代码 产品代码 测试代码 我们先写伪代码,伪代码 从意图层面来解决问题: 有了伪代码 我们用 ...
- 2018-2019-2 20175204 张湲祯 实验二《Java面向对象程序设计》实验报告
2018-2019-2-20175204 张湲祯 实验二 <Java开发环境的熟悉>实验报告 实验二 Java面向对象程序设计 一.实验内容: 初步掌握单元测试和TDD 理解并掌握面向对象 ...
- 2018-2019-2 20175218 实验二《Java面向对象程序设计》实验报告
2018-2019-2 20175218 实验二<Java面向对象程序设计>实验报告 一.面向对象程序设计-1 1.实验要求 参考 http://www.cnblogs.com/roced ...
- 2018-2019-2 20175126谢文航 实验二《Java面向对象程序设计》实验报告
一.实验报告封面 课程:Java程序设计 班级:1751 班 姓名:谢文航 学号:20175126 指导教师:娄嘉鹏 实验日期:2019年4月17日 实验时间:--- 实验序号:实验二 实验名称:Ja ...
- 2018-2019-2 20175234 实验二《Java面向对象程序设计》实验报告
目录 实验内容 实验要求 实验步骤 实验收获 参考资料 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 解设计模式 实验 ...
- 2017-2018-2 20165206 实验二《Java面向对象程序设计》实验报告
2017-2018-2 20165206 实验二<Java面向对象程序设计>实验报告 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:韩啸 学号:20165206 指导教 ...
随机推荐
- 其实每个行业都有各自的辛苦,好的程序员并不累,他们乐此不疲(见过太多在职位事业、人生方向上随转如流的人,累了疲乏了就去做别的事情了。必须有自己的坚守和立足的点,自我驱动,否则沦为在别人的体制制度中被驱赶一生)good
作者:陈柯好链接:https://www.zhihu.com/question/39813913/answer/104275537来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...
- 夯实基础:彻底搞清楚Cookie 和 Session 关系和区别(转)
原文地址:http://www.sohu.com/a/281228178_120047080 网络请求中的cookie与set-Cookie的交互模式和作用:https://my.oschina.ne ...
- 谷歌浏览器添加插件时显示程序包无效:"CRX_HEADER_INVALID" 解决办法
今天在添加谷歌插件的时候,却发现谷歌浏览器显示 程序包无效:"CRX_HEADER_INVALID",现整理解决方法如下: 下图是下载好的 .crx 结尾的插件. 将插件的后缀名改 ...
- jacascript 数组
前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! 数组的增删 第一个数组元素的索引值为 0,第二个索引值为 1,始终递增. 数组可以在头部增加元素arr.u ...
- Uniswap详解之一(概览)
一.Uniswap简介 Uniswap是以太坊上的DEX实现,基于"恒定乘积自动做市"模型,与传统的中心化和DEX具有很大的差别. 主要特点: 无订单簿,无做市商 兑换币具有很低的 ...
- 在IOS中根据圆心坐标、半径和角度计算圆弧上的点坐标
/** 日期:2015-10-15 版本: 1.0.0 -------------------------------------------------------------- 功能说明 ---- ...
- UITableView个人使用总结【前篇-增量加载】
UITableView现在边整边总结. 预计分两个部分,第一个部分主要是对UITableView本身属性的学习.第二个部分可能会是加上一个编辑按钮以及对列表的操作. 今天先学习第一部分. 第一部分,我 ...
- 新人数据库连接不上或数据库配置管理器里面sql服务打不开问题
新人在链接数据库时可能会出现链接不上数据库,这个问题解决方法是大家找到配置管理器里面,把那些停用的功能开启一下应该就可以.但是我们有的电脑还会遇到里面配置里面什么也没有的情况,这个时候我们就得到控制面 ...
- 华擎 J3455 主板装 Linux 系统
入手华擎J3455 ITX 主板,装备安装一个 redhat 来学习linux,及做一个家庭 web 服务器.但安装过程一波三折. 问题1.使用U盘引导不了,首先华擎这块板是 UEFI 板,用之前的老 ...
- 从win到多系统
相信有不少电脑爱好者喜欢折腾系统,尤其还是一个小白(感觉多系统强的不要不要的,各种崇拜),然后就走上了深渊. 首先,我一开始也是个win系统的忠实用户,没用过其他系统的我几乎不知道其他系统的存在,反正 ...