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

Thứ Ba, 8 tháng 1, 2019

UVa 12554 - A special ... Song (simulation)

Link:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=441&page=show_problem&problem=3999
Sol:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
const int size = 16;
string words[size] = {"Happy", "birthday", "to", "you", "Happy", "birthday", "to", "you", "Happy", "birthday", "to", "Rujia", "Happy", "birthday", "to", "you" };
int numPeople;
cin >> numPeople;
vector<string> names(numPeople);
for (int i = 0; i < numPeople; ++i)
cin >> names[i];
bool allGone = false;
for (int person = 0, cWord = 0; cWord < size || !allGone; ++person, ++cWord)
{
cWord %= size;
cout << names[person] << ": " << words[cWord] << '\n';
if (person + 1 == numPeople)
{
allGone = true;
person = -1;
}
}
}

UVa 12503 - Robot Instructions (easy simulation)

Link:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=441&page=show_problem&problem=3947
Sol:
#include <cstdio>
int main()
{
int T, N, move[101], posInMove, position, check;
char s[100];
scanf("%d", &T);
while (T--)
{
posInMove = position = 0;
scanf("%d", &N);
while (N--)
{
scanf("%s", s);
if (s[0] == 'L')
{
position += move[posInMove] = -1;
}
else if (s[0] == 'R')
{
position += move[posInMove] = 1;
}
else
{
scanf("%*s %d", &check);
position += move[posInMove] = move[check - 1];
}
++posInMove;
}
printf("%d\n", position);
}
}

UVa 12468 - Zapping( easy; there are only 4 possibilities)

Link:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=279&page=show_problem&problem=3912
Sol:
#include <cstdio>
#include <algorithm>
int main()
{
int first, second, one, two;
while (scanf("%d%d", &first, &second), first != -1)
{
if (first > second)
{
one = first - second;
two = second + 100 - first;
}
else
{
one = second - first;
two = first + 100 - second;
}
printf("%d\n", std::min(one, two));
}
}

UVa 12157 - Tariff Plan (LA 4405, KualaLumpur08, compute and compare)

Link:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=243&page=show_problem&problem=3309
Sol:
#include <cstdio>
int main()
{
int T, N, num, mileCost, juiceCost;
scanf("%d", &T);
for (int t = 1; t <= T; ++t)
{
scanf("%d", &N);
mileCost = juiceCost = 0;
while (N--)
{
scanf("%d", &num);
mileCost += (num / 30) * 10 + 10;
juiceCost += (num / 60) * 15 + 15;
}
printf("Case %d: ", t);
if (mileCost < juiceCost)
printf("Mile %d\n", mileCost);
else if (mileCost == juiceCost)
printf("Mile ");
if (juiceCost <= mileCost)
printf("Juice %d\n", juiceCost);
}
}

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