Codeforces-April Fools Day Contest 2020-E-图片坐标

119 阅读1分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

这是我做的图片(Codeforces@LetMeFly) 这是我做的图片(Codeforces@LetMeFly)

做了一张有坐标的图片,可能会帮助你解答E题 Having a picture with coordinates may help you solve E problem

E. Jordan Smiley time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output

Input The input contains two integers row, col (0≤row,col≤63), separated by a single space.

Output Output "IN" or "OUT".

这是题目的图片 (这是题目的图片) Examples input 0 0 output OUT input 27 0 output IN input 0 27 output OUT input 27 27 output IN

其实就是判断一个点的坐标在不在封闭图形内。 这是外国一大神的图片Codeforces@brezhart 外国大神的评论以及代码是:(Codeforces@brezhart) First: fill area in photoshop

Second: Do 2d dimension arr. Check pixel at (i15)+5 (g15)+5. If it's white, put 0 in arr else put 1; Save that arr in file for use it in final solution. I picked Node.JS for this step.

var fs = require("fs");
var Canvas = require("canvas");

let fileLink = "smile.png";
var canvas = new Canvas.Canvas(960, 960, "png");
var ctx = canvas.getContext("2d");

const Image = Canvas.Image;
var image = new Image(963,964);
dataArr = [];
image.onload = function () {
    ctx.drawImage(image,-2,-2,963,964);
    for (let i = 0; i < 64; i++){
        let newStr = [];
        for (let g = 0; g < 64; g++){
            var p = ctx.getImageData((g*15)+4, (i*15)+4, 1, 1).data;
            if (p[2] < 240){
                newStr.push(0)
            } else {
                newStr.push(1)
            }
        }
        dataArr.push(newStr)
    }
    fs.writeFileSync("DATAOUT.txt",JSON.stringify(dataArr))
};

image.src = fileLink; Final solution: just get row and col and check arr[row][col] if it's 0 print "OUT" else print "IN"

这需要时间啊 ^…………^

同步发文于我的CSDN