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

Thứ Năm, 10 tháng 1, 2019

UVa 12239 - Bingo (try all 90^2 pairs, see if all numbers in [0..N] are there)

Link:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=244&page=show_problem&problem=3391
Sol:
#include <cstdio>
#include <cmath>
#include <set>
using namespace std;
int main() {
int n, b, x[100];
while (scanf("%d %d", &n, &b), n || b) {
set<int> checker;
for (int i = 0; i < b; i++) {
scanf("%d", &x[i]);
}
for (int i = 0; i < b; i++) {
for (int j = i; j < b; j++) {
int d = abs(x[i] - x[j]);
if (d <= n)
checker.insert(d);
}
}
if (checker.size() == n + 1)
printf("Y\n");
else
printf("N\n");
}
return 0;
}

Thứ Tư, 9 tháng 1, 2019

UVa 11459 Snakes and Ladders * (simulate it, similar to UVa 647)

Link: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&page=show_problem&problem=2454
Sol:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int T;
cin >> T;
for (int i = 0; i < T; ++i)
{
int a, b, c;
cin >> a >> b >> c;
vector<int> playerPositions(a, 1), changeFromSpot(101, 0);
for (int z = 0; z < b; ++z)
{
int start, end;
cin >> start >> end;
changeFromSpot[start] = end - start;
}
bool won(false);
int change;
for (int z = 0; z < c; ++z)
{
cin >> change;
if (!won)
{
playerPositions[z % a] += change;
while (playerPositions[z % a] < 100 && changeFromSpot[playerPositions[z % a]] != 0)
playerPositions[z % a] += changeFromSpot[playerPositions[z % a]];
if (playerPositions[z % a] >= 100)
won = true;
}
}
for (int i = 0; i < a; ++i)
cout << "Position of player " << i + 1 << " is " << playerPositions[i] << ".\n";
}
}

UVa 10530 - Guessing Game (use a 1D flag array)

Link: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=17&page=show_problem&problem=1471
Sol: 
#include <cstdio>
#include <string.h>
int main()
{
int max, min, guess;
bool valid;
char input[12];
max = 11;
min = 0;
valid = true;
while (scanf("%d", &guess), guess)
{
scanf("%*s %s", input);
if (strcmp(input, "high") == 0)
{
if (guess <= min)
valid = false;
if (guess < max)
max = guess;
}
else if (strcmp(input, "low") == 0)
{
if (guess >= max)
valid = false;
if (guess > min)
min = guess;
}
else
{
if (guess > min && guess < max && valid)
{
printf("Stan may be honest\n");
}
else
{
printf("Stan is dishonest\n");
}
valid = true;
min = 0;
max = 11;
}
}
}

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ị: + ...