当前位置: 首页 > news >正文

2012金华邀请赛解题报告

这次的没学过的算法多了起来。尽管我都猜对了是用什么算法(我仅仅知道大体上各算法的原理,但没写过。

。)。。还有翻译上的严重失误。这次太慘了。。。

差点挂零。。

这次比赛的pdf地址:http://poj.org/ProblemDescriptions/jinghua.pdf

A题:

题目地址:POJ 4044

因为上次我在低端题上的失误。。

已被队友嫌弃。。。已经被剥夺写签到题的权利。。。

可是这题竟然被他俩弄了2小时也没AC。

。于是我不得不把题目又一次翻译了遍,自己敲了代码。

然后AC。。这题刚開始翻译错了,那个units digit在这里是个位数的意思。。sad。。

。题目非常easy。。直接上代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main()
{
    int t, n1, n2, i, j, n, m, x, pos1, pos2, max1, s, k, n3;
    int hash1[110], a[100], b[100], hash2[110], c[100];
    scanf("%d",&t);
    while(t--)
    {
        max1=-1;
        scanf("%d%d",&n,&m);
        memset(hash1,0,sizeof(hash1));
        memset(hash2,0,sizeof(hash2));
        for(i=0; i<n; i++)
        {
            scanf("%d",&x);
            hash1[x]++;
        }
        for(i=0; i<m; i++)
        {
            scanf("%d",&x);
            hash2[x]++;
        }
        n1=0;
        n2=0;
        for(i=100; i>=0; i--)
        {
            if(hash1[i])
            {
                a[n1++]=i;
            }
            if(hash2[i])
            {
                b[n2++]=i;
            }
        }
        for(i=0; i<n1; i++)
        {
            for(j=0; j<n2; j++)
            {
                if(a[i]==b[j])
                {
                    s=1;
                    for(k=1; i+k<n1&&j+k<n2; k++)
                    {
                        if(a[i+k]==b[j+k])
                        {
                            s++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if(max1<s)
                    {
                        max1=s;
                        pos1=i;
                    }
                    break;
                }
            }
        }
        if(max1==-1)
        {
            printf("NONE\n");
            continue ;
        }
        n3=0;
        for(i=pos1;i<pos1+max1;i++)
        {
            c[n3++]=a[i];
        }
        for(i=0;i<n3;i++)
        {
            printf("%d ",c[i]);
        }
        printf("\n");
        for(i=0;i<10;i++)
        {
            for(j=n3-1;j>=0;j--)
            {
                if(c[j]%10==i)
                {
                    printf("%d ",c[j]);
                }
            }
        }
        printf("\n");
    }
    return 0;
}

E题:

题目地址:POJ 4048

这题是shijun翻译的,他把题目意思翻译给了我跟+才。可是我理解的意思竟然跟他的原本意思相反,。更奇妙的是我理解的意思就是题目本来的意思。

。shijun翻译错了。

。。当时我感觉我的想法全然可行。。可是当场被他俩反驳了。。我以为是我理解错了意思。

。结果赛后找题解才发现。。那正确思路跟我当时想的做法是一模一样的。。。简直sad。

。。。因为昨晚有CF,也就没敲,今早起来一敲,把线段相交的模板一套。

就AC了。。

题目的思路是枚举线段的端点,每次把端点与原点形成一条射线。再遍历线段,求交点数。最后最多的交点数就是答案。复杂度1500*3000,轻松无压力。

代码例如以下:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include<algorithm>

using namespace std;
#define eps 1e-9
struct point
{
    double x;
    double y;
}p[4000];
int inter(point a, point b, point c, point d)
{
    if(min(a.x, b.x) > max(c.x, d.x) ||
            min(a.y, b.y) > max(c.y, d.y) ||
            min(c.x, d.x) > max(a.x, b.x) ||
            min(c.y, d.y) > max(a.y, b.y) )
        return 0;
    double h, i, j, k;
    h = (b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x);
    i = (b.x-a.x)*(d.y-a.y) - (b.y-a.y)*(d.x-a.x);
    j = (d.x-c.x)*(a.y-c.y) - (d.y-c.y)*(a.x-c.x);
    k = (d.x-c.x)*(b.y-c.y) - (d.y-c.y)*(b.x-c.x);
    return h*i <= eps && j*k <= eps;
}
int main()
{
    int t, n, i, j, n0, ans, max1;
    double x, y;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        n0=0;
        max1=-1;
        for(i=0;i<2*n;i++)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
        }
        scanf("%lf%lf",&x,&y);
        for(i=0;i<2*n;i++)
        {
            p[i].x-=x;
            p[i].y-=y;
        }
        point t1;
        t1.x=0;
        t1.y=0;
        for(i=0;i<2*n;i++)
        {
            point t2;
            t2.x=p[i].x*20000;
            t2.y=p[i].y*20000;
            ans=0;
            for(j=0;j<2*n;j+=2)
            {
                if(inter(t1,t2,p[j],p[j+1]))
                {
                    ans++;
                }
            }
            if(max1<ans)
                max1=ans;
        }
        printf("%d\n",max1);
    }
    return 0;
}


相关文章:

  • Java9 新特性 详解
  • 设置Google浏览器不缓存JS
  • IntelliJ Idea 常用快捷键列表
  • SpringCloud教程 | 第三篇: 服务消费者(Feign)
  • 前端远程调试
  • 与Brian Goetz聊Java的数据类
  • Git 系列(一):什么是 Git
  • 第十一章 LAMP架构
  • 《Arduino实战》——第1章 你好Arduino 1.1 Arduino简史
  • C++程序设计:原理与实践(进阶篇)17.7 使用Shape类
  • 微信小程序计算器后后续
  • 1020. 月饼 (25)
  • 防御XSS攻击的七条原则
  • Oralce分析函数
  • 《ANSYS 14热力学/电磁学/耦合场分析自学手册》——2.10 个性化界面
  • ES6指北【2】—— 箭头函数
  • [微信小程序] 使用ES6特性Class后出现编译异常
  • Debian下无root权限使用Python访问Oracle
  • Python - 闭包Closure
  • SpiderData 2019年2月25日 DApp数据排行榜
  • Vue小说阅读器(仿追书神器)
  • 程序员最讨厌的9句话,你可有补充?
  • 基于HAProxy的高性能缓存服务器nuster
  • 类orAPI - 收藏集 - 掘金
  • 理清楚Vue的结构
  • 如何选择开源的机器学习框架?
  • 如何用vue打造一个移动端音乐播放器
  • 数组的操作
  • 想使用 MongoDB ,你应该了解这8个方面!
  • 小程序01:wepy框架整合iview webapp UI
  • ​VRRP 虚拟路由冗余协议(华为)
  • # 计算机视觉入门
  • #define,static,const,三种常量的区别
  • (2.2w字)前端单元测试之Jest详解篇
  • (Bean工厂的后处理器入门)学习Spring的第七天
  • (Forward) Music Player: From UI Proposal to Code
  • (Python第六天)文件处理
  • (附源码)计算机毕业设计SSM在线影视购票系统
  • (五)Python 垃圾回收机制
  • (一)Java算法:二分查找
  • (一)Spring Cloud 直击微服务作用、架构应用、hystrix降级
  • (原創) 系統分析和系統設計有什麼差別? (OO)
  • (转)jdk与jre的区别
  • (转)mysql使用Navicat 导出和导入数据库
  • (转)Scala的“=”符号简介
  • (转)VC++中ondraw在什么时候调用的
  • .gitignore
  • .NET Micro Framework初体验
  • .NET Windows:删除文件夹后立即判断,有可能依然存在
  • .net 逐行读取大文本文件_如何使用 Java 灵活读取 Excel 内容 ?
  • .NET/C# 将一个命令行参数字符串转换为命令行参数数组 args
  • .net开源工作流引擎ccflow表单数据返回值Pop分组模式和表格模式对比
  • .NET设计模式(11):组合模式(Composite Pattern)
  • .NET应用架构设计:原则、模式与实践 目录预览
  • @ModelAttribute使用详解