Hiển thị các bài đăng có nhãn game(card). Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn game(card). Hiển thị tất cả bài đăng

Thứ Ba, 8 tháng 1, 2019

UVa 12247 - Jollo * (interesting card game; simple, but requires good logic to get all test cases correct)

Link:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=244&page=show_problem&problem=3399
Sol:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int> her(3), his(2);
vector<bool> available;
int card;
while (cin >> her[0] >> her[1] >> her[2] >> his[0] >> his[1], her[0])
{
available.clear();
available.resize(53, true);
for (int i = 0; i < 3; ++i)
{
available[her[i]] = false;
if (i < 2)
available[his[i]] = false;
}
sort(her.begin(), her.end());
sort(his.begin(), his.end());
card = 53;
// Both are higher
if (his[0] > her[2])
{
for (int i = 1; i <= 52 && i < card; ++i)
if (available[i])
card = i;
}
// One is higher than all
if (his[1] > her[2])
{
//printf("Here %d\n", her[2]);
for (int i = her[2] + 1; i <= 52 && i < card; ++i)
{
if (available[i])
card = i;
}
}
// Both higher than two of her cards
if (his[0] > her[1])
{
for (int i = her[1] + 1; i <= 52 && i < card; ++i)
if (available[i])
card = i;
}
if (card == 53)
card = -1;
cout << card << '\n';
}
}

UVa 11678 - Card's Exchange (actually just an array manipulation problem)

Link:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=78&page=show_problem&problem=2725
Sol:
#include <cstdio>
#include <map>
using namespace std;
int main()
{
map<int, bool> cards;
int aCards, bCards, current, aCount, bCount;
while (scanf("%d %d", &aCards, &bCards), aCards && bCards)
{
aCount = bCount = 0;
cards.clear();
for (int i = 0; i < aCards; ++i)
{
scanf("%d", &current);
if (cards.find(current) == cards.end())
{
++aCount;
cards[current] = true;
}
}
for (int i = 0; i < bCards; ++i)
{
scanf("%d", &current);
map<int, bool>::iterator iter = cards.find(current);
if (iter == cards.end())
{
cards[current] = false;
++bCount;
}
else if (iter->second)
{
iter->second = false;
--aCount;
}
}
printf("%d\n", aCount < bCount ? aCount : bCount);
}
}

Bài G - Educatioal Round 62

Đề bài: Bạn được cho 1 đồ thị vô hướng đặc biệt. Nó bao gồm $2n$ đỉnh được đánh số từ 1 đến 2n. Dưới đây là một số đặc tính của đồ thị: + ...