### Плата#

```#include <iostream>
using namespace std;

int main()
{
int p1, p2, p3;
cin >> p1 >> p2 >> p3;

if (p2-p1 == p3-p2) //aritmetichka progresija
{
cout << p3 + (p2-p1) << endl;
} else
{
cout << p3 * (p3/p2) << endl;
}

return 0;
}

```

### Комисија#

```#include <iostream>
#include <algorithm>
using namespace std;

const int MAX_N = 100;
const int INT_MAX = 2147483647;

int findMax(int A[], int n, int k) {
int M[MAX_N+1][MAX_N+1] = {0};
int cum[MAX_N+1] = {0};
for (int i = 1; i <= n; i++)
cum[i] = cum[i-1] + A[i-1];

for (int i = 1; i <= n; i++)
M[i][1] = cum[i];
for (int i = 1; i <= k; i++)
M[1][i] = A[0];

for (int i = 2; i <= k; i++) {
for (int j = 2; j <= n; j++) {
int best = INT_MAX;
for (int p = 1; p <= j; p++) {
best = min(best, max(M[p][i-1], cum[j]-cum[p]));
}
M[j][i] = best;
}
}
return M[n][k];
}

int main(){
int partitions, contests;
cin >> partitions >> contests;
int A[MAX_N];
for(int i = 0; i < contests; i++){
cin >> A[i];
}
cout << findMax(A, contests, partitions) << endl;
}
```

### Фудбалска лига#

```#include <iostream>
using namespace std;

int main()
{
int n, k;
cin >> n >> k;

int games = 2*(n-1);

int won=-1, drawn=-1, lost=-1;

for (int i=0; i<=games; i++)
for (int j=0; i+j<=games; j++)
{
if (3*i + j == k)
{
int cwon = i;
int cdrawn = j;
int clost = games - i - j;

if (lost==-1 || clost < lost)
{
won = cwon;
drawn = cdrawn;
lost = clost;
}
}
}

cout << won << " " << drawn << " " << lost << endl;
return 0;
}

```

### Торта#

```#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;

int length(int num)
{
if (num < 10)
return 1;
if (num < 100)
return 2;
if (num < 1000)
return 3;
if (num < 10000)
return 4;
if (num < 100000)
return 5;
if (num < 1000000)
return 6;
if (num < 10000000)
return 7;
if (num < 100000000)
return 8;
if (num < 1000000000)
return 9;

return 10;
}

int solve(int n)
{
int plen = 0, end = 0;

for (int i=1; ; i++)
{
plen += length(i); //vkupna dolzina na eden del (12345678910111213...)

if (n > plen) //ne e ovoj del, odi ponataka
{
n -= plen;
} else
{
end = i; //baranata cifra e vo delot 123456789101112---se do i (end)
break;
}
}

ostringstream oss; //pretvori go delot vo string

for (int j=1; j<=end; j++)
oss << j;

string res = oss.str();
return ((int)(res[n-1] - '0'));  //zemi cifra na baranata pozicija
}

int main()
{
int n;
cin >> n;

cout << solve(n) << endl;
return 0;
}

```

### Цезарова шифра#

```#include <iostream>
#include <string>
using namespace std;

char encode(char ch, int x)
{
string alphabet;
for (char c='a'; c<='z'; c++)
alphabet += c;

for (char c='y'; c>='a'; c--)
alphabet += c;

int pos = ch - 'a';
pos += x;

return alphabet[pos];
}

int main()
{
int x;
cin >> x;

string original;
cin >> original;

string encoded;

for (int i=0; i<original.size(); i++)
encoded += encode(x, original[i]);

cout << encoded << endl;
return 0;
}

```

### Оценување#

```#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int main()
{
int n;
cin >> n;

long long k;
cin >> k;

vector<long long> v;

for (int i=0; i<n; i++)
{
int ri;
cin >> ri;

v.push_back(ri);
}

long long sum = 0;
for (int i=0; i<n; i++)
sum += v[i];

if (sum <= k)
{
cout << "0" << endl;
return 0;
}

long long numCompetitorsLeft = n;
long long submissionsLeft = k;

while (numCompetitorsLeft > 0 && submissionsLeft > 0)
{
long long removeInTurn = submissionsLeft / numCompetitorsLeft;
if (removeInTurn <= 0)
break;

for (int i=0; i<n && numCompetitorsLeft>0 && submissionsLeft>0; i++)
{
if (v[i] > 0)
{
long long remove = min(removeInTurn, v[i]);
submissionsLeft -= remove;
v[i] -= remove;

if (v[i] == 0)
numCompetitorsLeft--;
}
}
}

//order is still {1, 2, 3, 4, 5, 6, ... , N}, except for those deleted
if (submissionsLeft > 0)
{
for (int i=0; i<n && numCompetitorsLeft>0 && submissionsLeft>0; i++)
{
if (v[i] > 0)
{
v[i]--;
submissionsLeft--;

if (v[i] == 0)
{
numCompetitorsLeft--;
}
}
}
}

cout << numCompetitorsLeft << endl;
return 0;
}

```

### Месечина#

```#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
double conn[500][500];

for (int i=0; i<500; i++)
for (int j=0; j<500; j++)
conn[i][j] = -1000;

int x[500], y[500];

int n;
cin >> n;

for (int i=0; i<n; i++)
{
int xi, yi;
cin >> xi >> yi;

x[i] = xi;
y[i] = yi;
}

for (int i=0; i<n; i++)
for (int j=i+1; j<n; j++)
{
int d2 = ((x[i]-x[j])*(x[i]-x[j])) + ((y[i]-y[j])*(y[i]-y[j]));
double d = sqrt(d2);

if (d2 <= 10*10)
conn[i][j] = conn[j][i] = d;
}

double distance[500];
int visited[500];

for (int i=0; i<500; i++)
{
visited[i] = 0;
distance[i] = 1e100; //10^100 - a very large number
}

distance[0] = 0;
int current = 0;

while (visited[current] == 0)
{
visited[current] = 1;

for (int i=0; i<n; i++)
if (visited[i] == 0)
if (conn[current][i] >= 0)
if (distance[i] > distance[current] + conn[current][i])
{
distance[i] = distance[current] + conn[current][i];
}

int next = -1;
double min = 1e100;

for (int i=0; i<n; i++)
if (visited[i] == 0)
if (distance[i] < min)
{
min = distance[i];
next = i;
}

if (next == -1)
break; //done

current = next;
}

cout << distance[n-1] << endl;
return 0;
}

```

### Калкулатор#

```#include <iostream>
using namespace std;

bool works[10];
int dp[5001];

void writeNumbers()
{
for (int i=0; i<10; i++)
if (works[i])
dp[i] = 1; //write 1 digit

for (int i=1; i<10; i++)
for (int j=0; j<10; j++)
if (works[i] && works[j])
dp[10*i + j] = 2; //write 2 digits

for (int i=1; i<10; i++)
for (int j=0; j<10; j++)
for (int k=0; k<10; k++)
if (works[i] && works[j] && works[k])
dp[100*i + 10*j + k] = 3; //write 3 digits

for (int i=1; i<10; i++)
for (int j=0; j<10; j++)
for (int k=0; k<10; k++)
for (int m=0; m<10; m++)
if (works[i] && works[j] && works[k] && works[m])
if (1000*i + 100*j + 10*k + m <= 5000)
dp[1000*i + 100*j + 10*k + m] = 4; //write 4 digits
}

void multiply()
{
//multiply
for (int i=0; i<=5000; i++)
for (int j=0; j<=5000; j++)
if (dp[i] >= 0 && dp[j] >= 0)
{
int where = min(i*j, 5000);

if (dp[where] < 0 || dp[where] > dp[i] + dp[j] + 1)
dp[where] = dp[i] + dp[j] + 1;
}
}

{
for (int i=0; i<=5000; i++)
for (int j=0; j<=5000; j++)
if (dp[i] >= 0 && dp[j] >= 0)
{
int where = min(i+j, 5000);

if (dp[where] < 0 || dp[where] > dp[i] + dp[j] + 1)
dp[where] = dp[i] + dp[j] + 1;
}
}

int main()
{
//initialize works[]
for (int i=0; i<10; i++)
works[i] = false;

//initialize dp[]
for (int i=0; i<5001; i++)
dp[i] = -1;

string allowed;
cin >> allowed;

for (int i=0; i<allowed.size(); i++)
works[((int)(allowed[i]-'0'))] = true;

writeNumbers();
multiply();

int target;
cin >> target;

cout << dp[target] << endl;
return 0;
}

```

Only authorized users are allowed to upload new attachments.
« This page (revision-2) was last changed on 28-Feb-2016 19:19 by filipdimitrovski
G’day (anonymous guest)
Материјали:

Натпревари 2013:

Натпревари 2012:

Натпревари 2011:

Натпревари 2010:

Системски:

JSPWiki v2.8.3