USACO 1.2.2 Transformations(模拟)
分析 这是我第一次在ACM的题目中用OO的思想写的程序,看到标程,竟不谋而合,结构是类的。对正方形这个类分析,将会使问题变得简单,我觉得OO的分析和设计挺关键的,其实我一开始也没设计好,原先准备把7个bool函数当成类的成员方法,其实这个设计是不好的,
分析
这是我第一次在ACM的题目中用OO的思想写的程序,看到标程,竟不谋而合,结构是类似的。对正方形这个类分析,将会使问题变得简单,我觉得OO的分析和设计挺关键的,其实我一开始也没设计好,原先准备把7个bool函数当成类的成员方法,其实这个设计是不好的,有点过了。其实应该是把旋转90度和轴对称这两个方法作为类的成员方法,这样main中调用就方便自如了。
最后,我觉得搞ACM,不仅是把题目A掉,同时也应注意程序的结构设计,因为”程序是给人看的“。
2013/3/31
关于顺时针旋转90度,怎么由原来的坐标得到转换后的坐标,可以用计算机图像学里二维变换的知识,将连续推广到离散的,如下图所示。
为了与二维数组对应,我将坐标系顺时针旋转了90度,这样就与二维数组的下标情况对应了,假设n为4。
关于变换矩阵,先把参考点移到原点,再顺时针旋转90度,最后移回原来参考点。复合变换矩阵:
MATLAB程序如下:
clc; clear all; syms x y n; P = [x y 1]; xF = (n - 1) / 2.0; % center = (xF yF) yF = xF; % theta = -pi / 2.0; Tt1 = [ 1 0 0; 0 1 0; -xF -yF 1 ]; % 精度有损失 % Tr = [ % cos(theta) sin(theta) 0; % -sin(theta) cos(theta) 0; % 0 0 1 % ]; Tr = [ 0 -1 0; 1 0 0; 0 0 1 ]; Tt2 = [ 1 0 0; 0 1 0; xF yF 1 ]; Pt = P * Tt1 * Tr * Tt2; display(P); display(Pt);
P = [ x, y, 1] Pt = [ y, n - x - 1, 1]
源程序
// #define ONLINE_JUDGE #define MY_DEBUG #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cassert> using namespace std; class Square { private: typedef vector<char> vChar; typedef vector<vchar> vvChar; vvChar data; unsigned n; public: // 用边长来构造 Square (unsigned _n) : n(_n) {} Square rotateClockwise90() { Square tmp(n); for (unsigned int i = 0; i data[n - 1 - j][i]); } tmp.data.push_back(vcTmp); } return tmp; } Square rotateClockwise180() { return this->rotateClockwise90().rotateClockwise90(); } Square rotateClockwise270() { return this->rotateClockwise180().rotateClockwise90(); } Square reflecteHorizontal() { Square tmp(n); for (unsigned int i = 0; i data[i][n - j - 1]); } tmp.data.push_back(vcTmp); } return tmp; } bool operator==(const Square &other) const { if (this->n != other.n) { return false; } for (unsigned i = 0; i data[i][j] != other.data[i][j]) { return false; } } } return true; } friend istream & operator>>(istream& is, Square &s) { for (unsigned int i = 0; i > cTmp; vcTmp.push_back(cTmp); } s.data.push_back(vcTmp); } return is; } friend ostream & operator= 1) { cout = 1) { cout > sideLen; Square sa(sideLen); Square sb(sideLen); cin >> sa >> sb; #ifndef MY_DEBUG cout <p><br> </p> <p><br> </p> <p><br> </p> <p>附:</p> <h3 id="标程">标程</h3> <p>注:它的旋转函数中坐标变换错了。</p> <pre class="brush:php;toolbar:false">#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #define MAXN 10 typedef struct Board Board; struct Board { int n; char b[MAXN][MAXN]; }; /* rotate 90 degree clockwise: [r, c] -> [c, n+1 - r] */ Board rotate(Board b) { Board nb; int r, c; nb = b; for(r=0; r<b.n r for c nb.b b.b return nb reflect board horizontally:> [r, n-1 -c] */ Board reflect(Board b) { Board nb; int r, c; nb = b; for(r=0; r<b.n r for c nb.b b.b return nb non-zero if and only boards are equal int eqboard b board bb bb.n bb.b rdboard n b.n="n;" getc assert void main file change fin='fopen("transform.in",' fout='fopen("transform.out",' null fscanf rotate else reflect fprintf exit><br> <h3 id="题目">题目</h3> <center> <strong><span>Transformations</span></strong><br> </center> <p>A square pattern of size N x N (1 </p> <ul> <li>#1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.</li> <li>#2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.</li> <li>#3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.</li> <li>#4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).</li> <li>#5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).</li> <li>#6: No Change: The original pattern was not changed.</li> <li>#7: Invalid Transformation: The new pattern was not obtained by any of the above methods.</li> </ul> <p>In the case that more than one transform could have been used, choose the one with the minimum number above.</p> <h3 id="PROGRAM-NAME-transform">PROGRAM NAME: transform</h3> <h3 id="INPUT-FORMAT">INPUT FORMAT</h3> <table> <tbody> <tr> <td>Line 1:</td> <td>A single integer, N</td> </tr> <tr> <td>Line 2..N+1:</td> <td>N lines of N characters (each either `@' or `-'); this is the square before transformation</td> </tr> <tr> <td>Line N+2..2*N+1:</td> <td>N lines of N characters (each either `@' or `-'); this is the square after transformation</td> </tr> </tbody> </table> <h3 id="SAMPLE-INPUT-file-transform-in">SAMPLE INPUT (file transform.in)</h3> <pre class="brush:php;toolbar:false">3 @-@ --- @@- @-@ @-- --@
OUTPUT FORMAT
A single line containing the the number from 1 through 7 (described above) that categorizes the transformation required to change from the `before' representation to the `after' representation.SAMPLE OUTPUT (file transform.out)
1

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

機器學習讓電腦繪圖(CG)模擬更真實了!方法名為神經流向圖(NeuralFlowMaps,NFM),四個渦旋的煙霧也能精確模擬的那種:更為複雜的也能輕鬆實現:要知道,在這個AI應用滿天飛的時代,CG物理仿真仍然是傳統數值演算法的天下。 △NFM模擬「蛙跳」儘管神經網路應用在CG能創造目眩神迷的視覺效果,它卻無法嚴格、魯棒地描述物理性質。 △NFM模擬「墨滴」也正是因此,基於神經網路的物理模擬至今仍處於概念驗證(proofofconcept)的階段,所產生的效果也遠非SOTA。為了解決這個複雜問題,

Transformer 已成為各種機器學習任務的熱門選擇,並且取得了很好的效果,那它還能怎麼用?腦洞大開的研究者竟然想用它來設計可程式計算機!這篇論文的作者來自普林斯頓大學和威斯康辛大學,標題為《Looped Transformers as Programmable Computers》,旨在探索如何用 Transformer 來實現通用電腦。具體來說,作者提出了一個將 transformer 網路用作通用電腦的框架,方法是使用特定權重對它們進行程式設計並將它們置於循環(loop)中。在這個框架

近日,三星公司宣布收購英國知識圖譜新創公司OxfordSemanticTechnologies,增強其本地AI功能,為用戶提供更個人化的AI體驗。該公司主要產品是AI引擎RDFox,透過知識圖譜技術,將資訊儲存為網路絡,處理資料的方式類似於人類的思考方式:獲取、記憶、回憶和推理知識。這項技術將增強設備對使用者使用產品或服務的理解,從而實現快速資訊檢索和推薦。據了解,OxfordSemanticTechnologies成立於2017年,由三位牛津大學教授伊恩·霍羅克斯、鮑里斯·莫蒂克和貝爾納多·昆卡

使用math/rand套件進行隨機數模擬:導入math/rand包。使用time.Now().UnixNano()初始化隨機數產生器。使用rand.Intn(n)產生0到n-1之間的隨機整數。使用rand.Float64()產生0到1之間的浮點數。

PHP和WebDriver擴充:如何模擬使用者的捲動和拖曳行為隨著網路應用的不斷發展,越來越多的網站和應用程式需要模擬使用者捲動和拖曳的行為。這對於測試人員和開發人員來說是非常重要的,以確保網站和應用程式在各種場景下都能正常運作。在本文中,我們將介紹如何使用PHP和WebDriver擴充功能來模擬使用者的捲動和拖曳行為。 WebDriver是一個用來自動化瀏覽器的工具,

如何利用GitLab進行API測試和模擬引言:在進行軟體開發過程中,API(ApplicationProgrammingInterface,應用程式介面)測試和模擬是非常重要的一步,它可以幫助開發人員驗證API的正確性和效能,並且可以提前發現潛在的問題。 GitLab是一個非常受歡迎的程式碼託管平台,實現了版本控制和團隊協作等功能。本文將介紹如何運用Git

蟒蛇和量子計算,這兩個看似遙遠且截然不同的領域,正以一種不可思議的方式相互交織,奏響了一曲算法與量子態的和諧之音,譜寫出一段數字世界的壯麗交響曲。蟒蛇的簡潔優雅與量子計算的奇妙玄妙,在交融中碰撞出無限的火花,為解決複雜問題提供了令人興奮的可能性,開啟了量子計算的新時代。蟒蛇作為一門流行的程式語言,憑藉其易於學習、豐富的函式庫和廣泛的應用,成為量子運算領域不可或缺的工具。蟒蛇的出現,降低了量子計算的門檻,使更多的人能夠參與這一前沿領域的研究和應用。蟒蛇的眾多庫,如NumPy和SciPy,為量子計算

1.引言JUnit是Java語言中最受歡迎的單元測試框架,它使得編寫和維護可讀性強、可維護性好且可靠的測試程式碼變得容易。本指南將提供逐步說明、程式碼範例和最佳實踐技巧,以幫助您有效地使用JUnit進行Java應用程式測試。 2.入門2.1設定測試項目在專案中新增JUnit依賴項以啟用測試功能。使用Maven時,在pom.xml檔案中加入以下相依性:junitjunit
