0% found this document useful (0 votes)
66 views14 pages

The Kitchen of The Dominos Pizza

The document contains multiple C programs that address various computational problems, including calculating areas, converting data sizes, graph traversal, string manipulation, and dynamic programming. Each program is structured with input handling, processing logic, and output generation. The programs demonstrate different algorithms and data structures to solve specific tasks efficiently.

Uploaded by

akhiljohnson2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views14 pages

The Kitchen of The Dominos Pizza

The document contains multiple C programs that address various computational problems, including calculating areas, converting data sizes, graph traversal, string manipulation, and dynamic programming. Each program is structured with input handling, processing logic, and output generation. The programs demonstrate different algorithms and data structures to solve specific tasks efficiently.

Uploaded by

akhiljohnson2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

The Kitchen of the Dominos Pizza

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

typedef struct { int r, h; } P;

double A(P p) { return 2 * M_PI * p.r * p.h; }

int cR(const void *a, const void *b) { return ((P *)b)->r - ((P *)a)->r; }

int cA(const void *a, const void *b) { return A(*(P *)b) - A(*(P *)a); }

int main() {

int T, N, K;

scanf("%d", &T);

while (T--) {

scanf("%d %d", &N, &K);

P p[N], t[N];

for (int i = 0; i < N; i++) scanf("%d %d", &p[i].r, &p[i].h);

qsort(p, N, sizeof(P), cR);

double m = 0;

for (int i = 0; i <= N - K; i++) {

double b = M_PI * p[i].r * p[i].r, l = A(p[i]);

int c = 0;

for (int j = i + 1; j < N; j++) t[c++] = p[j];

qsort(t, c, sizeof(P), cA);

for (int j = 0; j < K - 1; j++) l += A(t[j]);


if (b + l > m) m = b + l;

printf("%.9lf\n", m);

return 0;

}
FRY IS SUSPICIOUS
#include <stdio.h>

#include <string.h>

#include <math.h>

typedef struct { char u[3]; double v; } U;

U si[] = { {"B",1}, {"KB",1e3}, {"MB",1e6}, {"GB",1e9}, {"TB",1e12}, {"PB",1e15}, {"EB",1e18},


{"ZB",1e21} };

U bi[] = { {"B",1}, {"KiB",1024}, {"MiB",1048576}, {"GiB",1073741824},


{"TiB",1099511627776}, {"PiB",1125899906842624}, {"EiB",1152921504606846976} };

int main() {

double amt;

char u[3];

scanf("%lf %s", &amt, u);

int i = 0;

while (i < 8) {

if (!strcmp(u, si[i].u)) { amt *= si[i].v; break; }

i++;

for (i = 6; i >= 0; i--) {

if (amt >= bi[i].v) { amt /= bi[i].v; break; }

while(amt<1.0) amt *= 1024, i--;

printf("%.2lf %s\n", amt, bi[i].u);

return 0;

}
Aliens
#include <stdio.h>
#include <string.h>

#define MAX_NODES 20001

int visited[MAX_NODES];
int graph[MAX_NODES][MAX_NODES];
int degree[MAX_NODES];

int max(int a, int b) {


if (a > b)
return a;
else
return b;
}

int bfs(int start) {


int queue[MAX_NODES], front = 0, rear = 0;
int count[2] = {0, 0};

queue[rear++] = start;
visited[start] = 0;
count[0]++;

while (front < rear) {


int node = queue[front++];
int group = visited[node];

for (int i = 0; i < degree[node]; i++) {


int neighbor = graph[node][i];
if (visited[neighbor] == -1) {
visited[neighbor] = 1 - group;
count[visited[neighbor]]++;
queue[rear++] = neighbor;
} else {
continue;
}
}
}
return max(count[0], count[1]);
}

int main() {
int T, n, a, b;
scanf("%d", &T);

for (int test_case = 1; test_case <= T; test_case++) {


scanf("%d", &n);

for (int i = 0; i < MAX_NODES; i++) {


visited[i] = -1;
degree[i] = 0;
}

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


scanf("%d %d", &a, &b);
graph[a][degree[a]++] = b;
graph[b][degree[b]++] = a;
}

int max_size = 0;
for (int i = 0; i < MAX_NODES; i++) {
if (degree[i] > 0) {
if (visited[i] == -1) {
max_size += bfs(i);
} else {
continue;
}
} else {
continue;
}
}

printf("Line %d: %d\n", test_case, max_size);


}

return 0;
}
Level 3 topic 1

Dreamplay

#include <stdio.h>

#include <string.h>

int count(char *s, int n);

int count(char *s,int n) {

int l = 0, r = n - 1, c = 0;

while (l < r) {

if (s[l] != s[r]) c++;

l++, r--;

return c;

int main() {

char s[5001];

scanf("%s", s);

printf("%d\n", count(s, strlen(s)));

return 0;

}
You have been given 2 arrays
#include <stdio.h>

#include <stdlib.h>

typedef struct { int a, b; double r; } P;

int cmp(const void *x, const void *y) {

return ((P *)y)->r > ((P *)x)->r ? 1 : -1;

int main() {

int X, n;

scanf("%d %d", &X, &n);

P p[n];

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

scanf("%d %d", &p[i].a, &p[i].b);

p[i].r = (double)p[i].b / p[i].a;

qsort(p, n, sizeof(P), cmp);

int sumA = 0, sumB = 0,i;

for(i=0;i<n-1;i++) {

while (sumA + p[i].a <= X) {

sumA += p[i].a;

sumB += p[i].b;

if (sumA < X && p[n - 1].a + sumA <= X) {

sumA += p[n - 1].a;


sumB += p[n - 1].b;

printf("%d\n", sumB);

return 0;

}
You have a sequence of balls
#include <stdio.h>

#include <string.h>

#define INF 1000000000

typedef long long ll;

int n, a[501], dp[501][501];

ll find(ll l,ll r) {

if (l > r) return 0;

if (dp[l][r] != -1) return dp[l][r];

ll res = find(l + 1, r) + 1;

for (ll i = l + 1; i <= r; i++) {

if (a[i] == a[l]) {

ll temp = find(l + 1, i - 1) + find(i + 1, r);

if (temp < res) res = temp;

return dp[l][r] = res;

int main() {

scanf("%d", &n);

for (int i = 0; i < n; i++) scanf("%d", &a[i]);

memset(dp, -1, sizeof(dp));

printf("%lld\n", find(0, n - 1));

return 0;

}
Level 2 Topic 2
Aksha,Emma
#include <iostream>

#include <algorithm>

using namespace std;

int main() {

int n, q;

string s;

cin>>n>>q>>s;

while (q--) {

int l, r, k;

cin>>l>>r>>k;

if (k)

sort(s.begin() + l - 1, s.begin() + r);

else

sort(s.begin() + l - 1, s.begin() + r, greater<char>());

cout << s << endl;

return 0;

}
aabheer (topic2 medium)

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

int main() {
int n;
cin>>n;
int a[n];
map<int, int> freq;

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


cin>>a[i];
freq[a[i]]++;
}

int minVal = freq.begin()->first, maxVal = freq.rbegin()->first;


long long ways = (minVal == maxVal) ? (long long)n * (n - 1) / 2 : (long long)freq[minVal]
* freq[maxVal];

cout << maxVal - minVal << " " << ways << "\n";
return 0;
}
In the times of jhone and Greek(level 2 topic 3)

#include <iostream>

#include <string>

#include <vector>

using namespace std;

void ad(int &x,int y) {

int id;

int z;

int n;

int q;

x = (x + y) % 1000000007;

cin>>id>>z;

cin>>n>>q>>z;

int countOccurrences(const string &song, const string &name) {

int count = 0;

for (size_t i = 0; i <= song.length() - name.length(); ++i) {

if (song.substr(i, name.length()) == name) {

count++;

return count;

}
int main() {

int n, q;

cin >> n >> q;

string s0, t;

cin >> s0 >> t;

vector<string> songs(n + 1);

songs[0] = s0;

for (int i = 1; i <= n; ++i) {

songs[i] = songs[i - 1] + t[i - 1] + songs[i - 1];

for (int i = 0; i < q; ++i) {

int k;

string w;

cin >> k >> w;

int occurrences = countOccurrences(songs[k], w);

cout << occurrences << endl;

return 0;

You might also like