Yodda tuting! Ctrl + C & Ctrl + V bilan masalani tushunib qolmaysiz yoki bilimingiz oshib qolmaydi. Agar biror masalaning yechimiga tusuhunmagan bo'lsangiz, yechim videosini ko'rishni tavsiya etamiz. Videoda masalalar mazmunini va yechimini batafsil tushuntirishga harakat qildik.
Barcha yechimlar bir playlistda.
A. Sehrli kvadrat #2
#include <iostream>
using namespace std;
int main()
{
long long n, s;
cin >> n;
s = n*(n*n + 1)/2;
cout << s;
}
n = int(input())
s = n*(n*n+1)//2
print(s)
B. Shoh va Mot
Videoni ko'rish:
(1-qism)
(2-qism)
#include <bits/stdc++.h>
using namespace std;
int xq, yq, xo, yo, xf, yf;
bool a[10][10];
void reStart()
{
memset(a, false, sizeof a);
for(int i = 0; i < 10; i++)
{
a[0][i] = a[i][0] = a[i][9] = a[9][i] = true;
}
}
bool isKingWay(int x1, int y1, int x2, int y2)
{
bool b = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) <= 2;
return b;
}
double masofa(int x1, int y1, int x2, int y2)
{
return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}
bool isQueenWay(int x1, int y1, int x2, int y2)
{
bool b1, b2;
b1 = x1 == x2 || y1 == y2 || abs(x1-x2) == abs(y1-y2);
double m1,m2,m3;
m1 = masofa(x1,y1,x2,y2);
m2 = masofa(x1,y1,xo,yo);
m3 = masofa(x2,y2,xo,yo);
b2 = abs(m1 - (m2 + m3)) < 0.0001;
return b1 && !b2;
}
bool motmi(int x, int y)
{
for(int i = xq - 1; i <= xq + 1; i++)
{
for(int j = yq - 1; j <= yq + 1; j++)
{
if(!a[i][j])
{
if(isQueenWay(x,y,i,j)) a[i][j] = true;
}
}
}
if(isKingWay(xq,yq,x,y)) a[x][y] = false;
bool result = true;
for(int i = xq - 1; i <= xq + 1; i++)
{
for(int j = yq - 1; j <= yq + 1; j++)
{
if(!a[i][j])
{
if(isKingWay(xo,yo,i,j)) a[i][j] = true;
}
result = result && a[i][j];
}
}
return result;
}
string checking()
{
for(int i = 1; i < 9; i++)
{
for(int j = 1; j < 9; j++)
{
if(isQueenWay(xf,yf,i,j))
{
if(motmi(i,j))
{
return "MOT";
}
else
{
reStart();
}
}
}
}
return "DURRANG";
}
int main()
{
reStart();
string qoraShoh, oqShoh, farzin;
cin >> qoraShoh >> oqShoh >> farzin;
xq = qoraShoh[1] - 48;
xq = 9 - xq;
yq = qoraShoh[0] - 96;
xo = oqShoh[1] - 48;
xo = 9 - xo;
yo = oqShoh[0] - 96;
xf = farzin[1] - 48;
xf = 9 - xf;
yf = farzin[0] - 96;
cout << checking();
}
import math
a = [[False for _ in range(10)] for i in range(10)]
K = input()
k = input()
q = input()
def re_start():
global a
a = [[False for _ in range(10)] for _ in range(10)]
for i in range(10):
a[0][i] = a[i][0] = a[9][i] = a[i][9] = True
def mas(x1, y1, x2, y2):
return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
def is_king_way(x1, y1, x2, y2):
return (x1 - x2) ** 2 + (y1 - y2) ** 2 <= 2
def is_queen_way(qx, qy, x, y):
kx = int(k[1])
kx = 9 - kx
ky = ord(k[0]) - 96
b1 = qx == x or qy == y
b2 = abs(qx - x) == abs(qy - y)
m1 = mas(qx, qy, x, y)
m2 = mas(qx, qy, kx, ky)
m3 = mas(kx, ky, x, y)
b3 = int(m1 * 1000) != int((m2 + m3) * 1000)
return (b1 or b2) and b3
def asos(qx, qy):
kx = ord(k[1]) - 48
kx = 9 - kx
ky = ord(k[0]) - 96
bx = ord(K[1]) - 48
bx = 9 - bx
by = ord(K[0]) - 96
for i in range(bx - 1, bx + 2):
for j in range(by - 1, by + 2):
if not a[i][j]:
if is_queen_way(qx, qy, i, j):
a[i][j] = True
if is_king_way(bx, by, qx, qy):
a[qx][qy] = False
for i in range(bx - 1, bx + 2):
for j in range(by - 1, by + 2):
if not a[i][j]:
if is_king_way(kx, ky, i, j):
a[i][j] = True
bo = True
for i in range(bx - 1, bx + 2):
for j in range(by - 1, by + 2):
bo = bo and a[i][j]
return bo
re_start()
kx = int(k[1])
kx = 9 - kx
ky = ord(k[0]) - 96
qx = int(q[1])
qx = 9 - qx
qy = ord(q[0]) - 96
bx = int(K[1])
bx = 9 - bx
by = ord(K[0]) - 96
for i in range(1, 9):
for j in range(1, 9):
if is_queen_way(qx, qy, i, j):
if asos(i, j):
print("MOT")
exit()
else:
re_start()
print("DURRANG")
C. To'g'ri taqsimlash
#include <iostream>
using namespace std;
int main()
{
long long a, b, c, p, x, y;
cin >> a >> b >> p;
c = a + b;
x = p*(3*a - c)/c;
if (a > 2*b) x = p;
if (b > 2*a) x = 0;
y = p - x;
cout << x << ' ' << y;
}
a,b,p = map(int,input().split())
aka = (2*a - b)*p//(a+b)
uka = p - aka
if aka < 0 :
aka,uka = 0,p
if uka < 0 : aka,uka = p,0
print(int(aka),int(uka))
D. Katta uchburchak yuzi.
#include <bits/stdc++.h>
using namespace std;
int lastDigit(string s)
{
return s[s.length() - 1] - 48;
}
int tbu(int x1, int y1, int x2, int y2, int x3, int y3)
{
int s = abs((x2*y3 + x1*y2 +y1*x3) - (x2*y1 + x1*y3 + x3*y2));
return s % 2;
}
int main()
{
int n, x1,y1,x2,y2,x3,y3;
string s1,c1,s2,c2,s3,c3;
cin >> n;
while(n--)
{
cin >> s1 >> c1;
cin>> s2 >> c2;
cin >> s3 >> c3;
//.0 .5
x1 = lastDigit(s1);
y1 = lastDigit(c1);
x2 = lastDigit(s2);
y2 = lastDigit(c2);
x3 = lastDigit(s3);
y3 = lastDigit(c3);
int g = tbu(x1,y1,x2,y2,x3,y3);
if( g % 2 == 0) cout << "Yes\n";
else cout << "No\n";
}
}
def method(x1, y1, x2, y2, x3, y3):
a = abs((x2*y3 + x1*y2 + y1*x3) - (x2*y1 + x1*y3 + x3*y2))
return a % 2 == 0
def D(x):
return int(x[-1]) % 2
t = int(input())
for _ in range(t):
x1, y1 = input().split()
x2, y2 = input().split()
x3, y3 = input().split()
f = input()
xx1, yy1, xx2, yy2, xx3, yy3 = map(D, [x1, y1, x2, y2, x3, y3])
if method(xx1, yy1, xx2, yy2, xx3, yy3):
print("Yes")
else:
print("No")
E. Devordagi soat #1
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int s, m, a;
double v;
char c;
cin >> s >> c >> m;
s = 300*s + 5 * m;
m = m * 60;
a = s - m;
a = (a + 3600) % 3600;
v = a*12/11.0;
cout << trunc(v);
}
import math
s, m = map(int, input().split(':'))
s = 300 * s + 5 * m
m = m * 60
a = s - m
a = (a + 3600) % 3600
v = a * 12 / 11
print(math.trunc(v))
F. Devordagi soat #2
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char c;
int s, m;
double a;
cin >> s >> c >> m;
a = s*30 + m/2.0;
m = m * 6;
a = abs(a - m);
if (a > 180) a = 360 - a;
cout << fixed << setprecision(2) << a;
}
s, m = map(int,input().split(':'))
a = s * 30 + m / 2
m = m * 6
a = abs(a - m)
if a > 180:
a = 360 - a
print("{:.2f}".format(a))
G. Kim aytadi? (Interactive)
#include <iostream>
using namespace std;
int main()
{
int n , k , a, b;
cout << 0 << endl;
cout.flush();
cin >> n >> k;
a = n %(k+1);
while(a < n)
{
cout << a << endl;
cout.flush();
cin >> b;
a += k+1;
}
cout << a << endl;
cout.flush();
}
import sys
print(0)
sys.stdout.flush()
n,k = map(int,input().split())
a = n % (k+1)
while a < n:
print(a)
sys.stdout.flush()
b = int(input())
a = a + k + 1
print(a)
sys.stdout.flush()
H. Parallelpiped Sum
Eratosfen g'alviri haqida batafsil video
Prefix Sum haqida batafsil video
Masala yechimi videosi:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 107;
int a[maxn][maxn][maxn];
vector<bool> galvir(maxn,true);
void Eratosfen()
{
galvir[0] = galvir[1] = false;
for(int p = 2; p*p < maxn; p++)
{
if(galvir[p])
{
for(int i = p*p; i < maxn; i+=p)
{
galvir[i] = false;
}
}
}
}
void filling()
{
for(int i = 1; i < maxn; i++)
{
for(int j = 1; j < maxn; j++)
{
for(int k = 1; k < maxn; k++)
{
if(galvir[i] && galvir[j] && galvir[k])
{
a[i][j][k] = i * j * k;
}
else
{
a[i][j][k] = i + j + k;
}
}
}
}
}
void prefSum()
{
for(int i = 1; i < maxn; i++)
{
for(int j = 1; j < maxn; j++)
{
for(int k = 1; k < maxn; k++)
{
a[i][j][k] += a[i-1][j][k] + a[i][j-1][k] + a[i][j][k-1];
a[i][j][k] -= a[i][j-1][k-1] + a[i-1][j][k-1] + a[i-1][j-1][k];
a[i][j][k] += a[i-1][j-1][k-1];
}
}
}
}
int qismSum(int i1, int j1, int k1,int i2, int j2, int k2)
{
return a[i2][j2][k2] - a[i1-1][j2][k2] - a[i2][j1 - 1][k2] - a[i2][j2][k1-1] +
a[i2][j1-1][k1-1] + a[i1-1][j2][k1-1] + a[i1-1][j1-1][k2] - a[i1-1][j1-1][k1-1];
}
int main()
{
Eratosfen();
filling();
prefSum();
ifstream fin("input.txt");
ofstream fout("output.txt");
int q, i1,j1,k1,i2,j2,k2;
fin >> q;
while(q--)
{
fin >> i1 >> j1 >> k1 >> i2 >> j2 >> k2;
if(i1 > i2) swap(i1,i2);
if(j1 > j2) swap(j1,j2);
if(k1 > k2) swap(k1,k2);
fout << qismSum(i1,j1,k1,i2,j2,k2) << endl;
}
fin.close();
fout.close();
}
maxn = 103
a = [[[0 for _ in range(maxn)] for _ in range(maxn)] for _ in range(maxn)]
prm = [True] * (maxn + 1)
def Erotosfen():
prm[0] = prm[1] = False
for p in range(2, int(maxn**0.5) + 1):
if prm[p]:
for i in range(p * p, maxn + 1, p):
prm[i] = False
for x in range(1, maxn):
for y in range(1, maxn):
a[i][x][y] = a[x][i][y] = a[x][y][i] = i + x + y
for x in range(1, maxn):
for y in range(1, maxn):
a[1][x][y] = a[x][1][y] = a[x][y][1] = 1 + x + y
ssss = 0
def Pref():
global ssss
for i in range(1, maxn):
for j in range(1, maxn):
for k in range(1, maxn):
if a[i][j][k] == 0:
a[i][j][k] = i * j * k
ssss += a[i][j][k]
a[i][j][k] += a[i-1][j][k] + a[i][j-1][k] + a[i][j][k-1] - a[i-1][j-1][k] - a[i-1][j][k-1] - a[i][j-1][k-1] + a[i-1][j-1][k-1]
def Sum(x1, y1, z1, x2, y2, z2):
return a[x2][y2][z2] - a[x1-1][y2][z2] - a[x2][y1-1][z2] - a[x2][y2][z1-1] + a[x1-1][y1-1][z2] + a[x1-1][y2][z1-1] + a[x2][y1-1][z1-1] - a[x1-1][y1-1][z1-1]
Erotosfen()
Pref()
fin = open('input.txt','r')
fout = open("output.txt",'w')
q = int(fin.readline())
for _ in range(q):
x, y, z, h, w, n = map(int, fin.readline().split())
if x > h: x, h = h, x
if y > w: y, w = w, y
if z > n: z, n = n, z
fout.write(str(Sum(x, y, z, h, w, n)) + '\n')
fin.close()
fout.close()