Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Flood/Debug/Flood.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
 Source.cpp
Flood.vcxproj -> c:\users\nicholasly\documents\visual studio 2015\Projects\Flood\Debug\Flood.exe
Flood.vcxproj -> c:\users\nicholasly\documents\visual studio 2015\Projects\Flood\Debug\Flood.pdb (Partial PDB)
Binary file added Flood/Debug/Flood.tlog/CL.command.1.tlog
Binary file not shown.
Binary file added Flood/Debug/Flood.tlog/CL.read.1.tlog
Binary file not shown.
Binary file added Flood/Debug/Flood.tlog/CL.write.1.tlog
Binary file not shown.
2 changes: 2 additions & 0 deletions Flood/Debug/Flood.tlog/Flood.lastbuildstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
Debug|Win32|c:\users\nicholasly\documents\visual studio 2015\Projects\Flood\|
Binary file added Flood/Debug/Flood.tlog/link.command.1.tlog
Binary file not shown.
Binary file added Flood/Debug/Flood.tlog/link.read.1.tlog
Binary file not shown.
Binary file added Flood/Debug/Flood.tlog/link.write.1.tlog
Binary file not shown.
Binary file added Flood/Debug/Source.obj
Binary file not shown.
Binary file added Flood/Debug/vc140.idb
Binary file not shown.
Binary file added Flood/Debug/vc140.pdb
Binary file not shown.
118 changes: 118 additions & 0 deletions Flood/Flood.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{F920F49A-5688-4230-B532-D2DFB24C1007}</ProjectGuid>
<RootNamespace>Flood</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Source.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
22 changes: 22 additions & 0 deletions Flood/Flood.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Source.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
32 changes: 32 additions & 0 deletions Flood/Source.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>
#include <set>
#include <vector>
#include <string>
using namespace std;
int main() {
int n, m;
while (cin >> n && n) {
set<string> name;
cin >> m;
for (int i = 0; i < n; i++) {
string temp;
cin >> temp;
for (int j = 0; temp[j] != '\0'; j++) {
if (temp[j] >= 'A' && temp[j] <= 'Z') temp[j] += 32;
}
name.insert(temp);
}
set<string> sent;
for (int i = 0; i < m; i++) {
string temp;
cin >> temp;
for (int j = 0; temp[j] != '\0'; j++) {
if (temp[j] >= 'A' && temp[j] <= 'Z') temp[j] += 32;
}
if (name.find(temp) == name.end()) continue;
sent.insert(temp);
}
cout << n - sent.size() << endl;
}
return 0;
}
71 changes: 71 additions & 0 deletions KnightMoves(BFS)/KnightMoves.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

int startx, starty, endx, endy;
int used[9][9];
int mov[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{1,-2},{-1,2},{-1,-2}};

static int i = []() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
return 0;
}();

struct node {
int x, y;
};

bool issafe(int x, int y) {
return (x > 0 && y > 0 && x <= 8 && y <= 8 && used[x][y] == 0);
}

int main() {
int T;
cin >> T;
while (T--) {
char a, b;
cin >> a >> startx;
starty = a - 'b';
cin >> b >> endx;
endy = b - 'b';

node no;
no.x = startx;
no.y = starty;
int step = 0, flag = 0;

vector<node> v[64];
v[0].push_back(no);
memset(used, 0, sizeof(used));
used[startx][starty] = 1;

if (startx != endx || starty != endy) {
while (1) {
vector<node>::iterator it;
for (it = v[step].begin(); it != v[step].end(); it++) {
node f = * it;
for (int i = 0; i < 8; i++) {
node temp;
temp.x = f.x + mov[i][0];
temp.y = f.y + mov[i][1];
if (temp.x == endx && temp.y == endy) {
flag = 1;
break;
}
if (issafe(temp.x, temp.y)) {
v[step + 1].push_back(temp);
used[temp.x][temp.y] = 1;
}
}
if (flag == 1) break;
}
step++;
if (flag == 1) break;
}
}
cout << "To get from " << a << startx << " to " << b << endx << " takes " << step << " knight moves." << endl;
}
return 0;
}
53 changes: 53 additions & 0 deletions KnightMoves(BFS)/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
1000. Knight Moves

Time Limit: 1sec Memory Limit:32MB

Description

A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n squares on a chessboard exactly once. He thinks that the most difficult part of the problem is determining the smallest number of knight moves between two given squares and that, once you have accomplished this, finding the tour would be easy. Of course you know that it is vice versa. So you offer him to write a program that solves the "difficult" part. Your job is to write a program that takes two squares a and b as input and then determines the number of knight moves on a shortest route from a to b.

Input

There are multiple test cases. The first line contains an integer T, indicating the number of test cases. Each test case consists of one line containing two squares separated by one space. A square is a string consisting of a letter (a-h) representing the column and a digit (1-8) representing the row on the chessboard.

Output

For each test case, print one line saying "To get from xx to yy takes n knight moves.".

Sample Input

8

e2 e4

a1 b2

b2 c3

a1 h8

a1 h7

h8 a1

b1 c3

f6 f6

Sample Output

To get from e2 to e4 takes 2 knight moves.

To get from a1 to b2 takes 4 knight moves.

To get from b2 to c3 takes 2 knight moves.

To get from a1 to h8 takes 6 knight moves.

To get from a1 to h7 takes 5 knight moves.

To get from h8 to a1 takes 6 knight moves.

To get from b1 to c3 takes 1 knight moves.

To get from f6 to f6 takes 0 knight moves.
62 changes: 62 additions & 0 deletions MagicSquare/MagicSquareA.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <iostream>
using namespace std;

int main() {
int n;
cin >> n;
int **p = new int*[n];
for (int i = 0; i < n; i++) {
p[i] = new int[n];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> p[i][j];
}
}
bool flag = true;
int sum = 0;
for (int i = 0; i < n; i++) {
sum += p[0][i];
}
for (int i = 0; i < n; i++) {
int temp = 0;
for (int j = 0; j < n; j++) {
temp += p[i][j];
}
if (temp != sum) {
flag = false;
break;
}
}

for (int i = 0; i < n; i++) {
int temp = 0;
for (int j = 0; j < n; j++) {
temp += p[j][i];
}
if (temp != sum) {
flag = false;
break;
}
}

int temp = 0;
for (int i; i < n; i++) {
temp += p[i][i];
}
if (temp != sum) flag = false;

temp = 0;
for (int i = 0; i < n; i++) {
temp += p[i][n - i - 1];
}
if (temp != sum) flag = false;
if (flag) cout << "Yes!" << endl;
else cout << "No!" << endl;
for (int i = 0; i < n; i++) {
delete [] p[i];
}
delete [] p;
return 0;
}

Loading