Skip to content

Commit

Permalink
Add Reference & change code encode
Browse files Browse the repository at this point in the history
  • Loading branch information
Voleking committed Sep 14, 2017
1 parent cf5ed1b commit 6b93659
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
Binary file added Reference/ACM-ICPC-CodeTemplate-Latex-master.zip
Binary file not shown.
Binary file added Reference/algorithmic-library-master.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// UVa10305 Ordering Tasks
// Rujia Liu
// 题意:输入n和m,以及m个二元组(i,j),求1~n的一个排列使得对于每个(i,j),i在j的前面
// 算法:拓扑排序。注意m可能等于0
// 题意:输入n和m,以及m个二元组(i,j),求1~n的一个排列使得对于每个(i,j),i在j的前面
// 算法:拓扑排序。注意m可能等于0
#include<cstdio>
#include<cstring>
const int maxn = 1000;
Expand Down Expand Up @@ -39,6 +39,6 @@ int main() {
printf("%d\n", topo[n-1]+1);
}
else
printf("No\n"); // 题目没说无解输出什么,应该是保证有解吧
printf("No\n"); // 题目没说无解输出什么,应该是保证有解吧
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Rujia Liu
/*
题意:
题意:
把52张牌从左到右排好,每张牌自成一个牌堆(pile)。
当某张牌与它左边那张牌或者左边第三张牌“match”(花色suit或者点数rank相同)的时候,就把这张牌移到那张牌上面去。
移动之后还要看看是否可以进行其他的移动。只有位于牌堆顶部的牌才能移动或者参与match。
当牌堆之间出现空隙的时候要立刻把右边的所有牌堆左移一格来填补空隙。
如果有多张牌可以移动,先移动最左边的那张牌;如果既可以移一格也可以移三格的时候,移三格。
把52张牌从左到右排好,每张牌自成一个牌堆(pile)。
当某张牌与它左边那张牌或者左边第三张牌“match”(花色suit或者点数rank相同)的时候,就把这张牌移到那张牌上面去。
移动之后还要看看是否可以进行其他的移动。只有位于牌堆顶部的牌才能移动或者参与match。
当牌堆之间出现空隙的时候要立刻把右边的所有牌堆左移一格来填补空隙。
如果有多张牌可以移动,先移动最左边的那张牌;如果既可以移一格也可以移三格的时候,移三格。
算法:每堆牌是一个栈,各个牌堆形成一个链表。为了方便判断和存储,牌(rank, suit)转化成整数rank*4+suit
算法:每堆牌是一个栈,各个牌堆形成一个链表。为了方便判断和存储,牌(rank, suit)转化成整数rank*4+suit
*/

Expand All @@ -29,7 +29,7 @@ struct Pile {
int pop() { return cards[t--]; }
void push(int v) { cards[++t] = v; }
bool empty() const { return t == -1; }
} pile[ncard+1]; // pile[52]是虚拟堆
} pile[ncard+1]; // pile[52]是虚拟堆

const char* suits = "CDHS";
const char* ranks = "A23456789TJQK";
Expand All @@ -52,7 +52,7 @@ bool read_input() {
return true;
}

// 第p堆左边k堆的编号
// 第p堆左边k堆的编号
int left(int p, int k) {
while(k--) {
p = pile[p].prev;
Expand All @@ -65,7 +65,7 @@ inline int match(int card1, int card2) {
return card1 % 4 == card2 % 4 || card1 / 4 == card2 / 4;
}

// 牌堆p顶部的牌是否可以移动
// 牌堆p顶部的牌是否可以移动
bool can_move(int p) {
int card = pile[p].top();
int p1 = left(p, 1);
Expand All @@ -85,7 +85,7 @@ void move(int p) {
if(p1 >= 0 && match(card, pile[p1].top())) { cur = p1; continue; }
break;
}
// 从p移动到cur
// 从p移动到cur
pile[p].pop();
pile[cur].push(card);
if(pile[p].empty()) {
Expand All @@ -98,17 +98,17 @@ int main() {
for(;;) {
if(!read_input()) break;
for(;;) {
// 找一张可以移动的牌
// 找一张可以移动的牌
int p = 0;
while(p < ncard) {
if(can_move(p)) break;
p = pile[p].next;
}
if(p == ncard) break; // 无牌可以移动
if(p == ncard) break; // 无牌可以移动
move(p);
}

// 输出
// 输出
vector<int> ans;
int p = 0;
while(p < ncard) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// UVa439 Knight Moves
// Rujia Liu
// 题意:输入标准国际象棋棋盘上的两个格子,求马最少需要多少步从起点跳到终点
// 题意:输入标准国际象棋棋盘上的两个格子,求马最少需要多少步从起点跳到终点
#include<cstdio>
#include<cstring>
#include<queue>
Expand Down

0 comments on commit 6b93659

Please sign in to comment.