Ilovepdf Merged
Ilovepdf Merged
SIGNATURE SIGNATURE
1.
#include <iostream>
using namespace std;
int main() {
int t;
long long width, height, area;
scanf("%d", &t);
#include<bits/stdc++
.h> using namespace
std; int main()
{
int t; cin>>t; while(t--){
int b,n,r; cin>>b>>n>>r; int
z=1; for(int i=1;i<=n;i++){
z=z*i;
}
int res; res=pow(b,z); cout<<res%r<<endl;
}
return 0; cout<<"if(n%2==1)";
}
3.
#include <iostream>
using namespace std;
int main() {
int cases;
cin >> cases;
q = q + (r - 1) / 5;
r = (r - 1) % 5 + 1;
p = p + (q - 1) / 10;
q = (q - 1) % 10 + 1;
cout << p << " " << q << " " << r << endl;
}
return 0; }
4.
#include <iostream>
#include <string>
using namespace std;
int main() {
string s, s2;
cin >> s >> s2;
int z = s.length();
int a[z];
for (int i = 0; i < z - 1; i++) {
a[i] = s[i + 1] - s[i];
}
for (int i = 0; i < z - 2; i++) {
if (a[i] != a[i + 1]) {
cout << "No";
return 0;
}
}
cout << "Yes";
return 0;
5.
#include <iostream>
using namespace std;
#define p1 cout << "Ace, move fast, pigeon is at (" << i << ",0)";
#define p2 cout << "Ace, move fast, pigeon is at (" << (i - i / z) % z << "," << i / z << ")";
#define p3 cout << "No pigeon, try another map, Ace";
#define a continue;
#define f(n) for (int i = 0; i < z; i++)
#define while1 while ((scanf("%c", &s[i])) != EOF)
int main() {
string s1;
cin >> s1;
int z = s1.size();
f(n) {
if (s1[i] == 'P') {
p1
return 0;
}
}
int i = 0, cnt = 0;
char s[10000];
while1 {
if (s[i] == 'P') {
cnt = 1;
break;
}
i++;
}
if (cnt == 1) p2
else p3
}
6.
#include <iostream>
using namespace std;
int factors(int num, int l) {
int c1 = 0;
for (int i = 1; i <= num; i++) {
if (num % i == 0 && i > l) {
c1++;
}
}
return c1;
}
int main() {
int t, j;
cin >> t;
for (j = 1; j <= t; j++) {
int p, l, q, i, c = 0, sp;
cin >> p >> l;
q = p - l;
printf("Line %d: ", j);
sp = factors(q, l);
for (i = 1; i <= q; i++) {
if (q % i == 0 && i > l) {
printf("%d", i);
if (c < sp - 1) {
printf(" ");
}
c++;
}
}
if (c == 0) {
printf("impossible");
}
printf("\n");
}
return 0;
}
7.
#include <iostream>
using namespace std;
int main() {
#include <iostream>
#include <cstring>
using namespace std;
int main() {
int n, i, j, t;
cin >> n;
for (i = 0; i < n; i++) {
cout << "Line " << i + 1 << ":" << endl;
cin >> t;
int sum = 0;
for (j = 0; j < t; j++) {
char name[100];
cin >> name;
if (strcmp(name, "donate") == 0) {
int donation;
cin >> donation;
sum += donation;
} else {
cout << sum << endl;
}
}
}
return 0;
}
9.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=(int)1e6+6,mod=(int)0;
int a[N];
long long sum[N];
int main(){
int tc;
cin>>tc;
for(int tt=1;tt<=tc;++tt){
int n,p;
cin>>n>>p;
for(int j=0;j<n;++j)
cin>>a[j];
sort(a,a+n);
int i;
for(i=0;i<n;i++) sum[i+1]=sum[i]+a[i];
long long res=1e18;
for(int j=p-1;j<n;++j){
long long s=sum[j+1]-sum[j-(p-1)];
long long cost=(LL)a[j]*p-s;
res=min(res,cost);
}
cout<<res<<'\n';
}
}
10.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf = 1e9;
const int N = 62;
char word[N];
ll dp[N][N];
long long calculate(int s,int e)
{
if (s > e)
return 0;
if (s ==e)
return 1; ll &p = dp[s][e];
if (p != -1)
return p; p = 0;
if (word[s] == word[e]) p = 1 + calculate(s+1, e-1);
p += (calculate (s+1, e) + calculate (s, e-1) - calculate (s+1, e-1));
return p;
}
int main ()
{
ll res;
cin>>word;
memset (dp, -1, sizeof (dp));
res = calculate (0, strlen(word)-1);
printf ("%lld\n", res);
return 0;
}
11.
#include<bits/stdc++.h>
using namespace std;
int h,q,v,e;
string str;
map<int,int> f;
double puzzle(int u,int mx) {return (f[u]<=mx)?mx:(0.5*(puzzle(u<<1,max(mx,f[u]-
f[u<<1]))+puzzle(u<<1|1,max(mx,f[u]-f[u<<1|1]))));}
int main(){
cin>>h>>q;
while (q--){
cin>>str;
if (str[0]=='a'){
scanf("%d %d",&v,&e);
while (v) f[v]+=e,v>>=1;
}
else printf("%.2lf\n",puzzle(1,0));
}
return 0;
}
12.
#include <iostream>
#include <string>
using namespace std;
void garbage() {
cout << "int go(int f, int s) cin >> a; ";
}
int findMinInsertions(string str, int l, int h) {
if (l > h) return INT_MAX;
if (l == h) return 0;
if (l == h - 1) return (str[l] == str[h]) ? 0 : 1;
return (str[l] == str[h]) ?
findMinInsertions(str, l + 1, h - 1) :
(min(findMinInsertions(str, l, h - 1), findMinInsertions(str, l + 1, h)) + 1);
}
int main() {
string s;
cin >> s;
cout << findMinInsertions(s, 0, s.length() - 1);
return 0;
}
13.
#include <iostream>
using namespace std;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
p[a[i]] = i;
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= min(n, i + 5); j++) {
if (a[i] * 2 - a[j] > 0 && a[i] * 2 - a[j] <= n && p[a[i] * 2 - a[j]] < i)
return puts("YES"), 0;
if (a[j] * 2 - a[i] > 0 && a[j] * 2 - a[i] <= n && p[a[j] * 2 - a[i]] > j)
return puts("YES"), 0;
}
}
puts("NO");
return 0;
}
14.
#include <iostream>
using namespace std;
#define f(n) for(n = n; n > 0; --n)
int main() {
int n, r = 0, m = 100, x, y;
cin >> n;
f(n) {
cin >> x >> y;
if (y < m)
m = y;
r += m * x;
}
printf("%d", r);
}
15.
#include<bits/stdc++.h>
using namespace std;
map<maxs, maxs> a;
maxs i, n, k, x, p;
int main() {
cin >> n;
for (; i < n; i++) {
cin >> x;
k += x;
a[k]++;
p = max(p, a[k]);
}
cout << n – p;
}
16.
#include <iostream>
using namespace std;
int a[3];
int main() {
int n, x, i;
cin >> n;
return 0;
}
17.
#include<bits/stdc++.h>
using namespace std;
int n,l,z;
pair<int,int> a[500020];
int main(){
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i].second>>a[i].first;
}
sort(a,a+n);
for(int i=0;i<n;i++)
{
if(l<a[i].second)
{
z++;
l=a[i].first;
}
}cout<<z;
return 0;
}
18.
#include <iostream>
using namespace std;
int n, m, s, a, b, d[11];
int main() {
cin >> n >> m;
while (m--)
cin >> a >> b, d[b] += a;
cout << s;
return 0;
}
19.
#include <iostream>
using namespace std;
int p = 1, n, j, a[105];
char c;
int main() {
a[j++] = 1;
while (cin >> c && c != '=') {
if (c == '-')
p--, a[j++] = -1;
if (c == '+')
p++, a[j++] = 1;
}
cin >> n;
for (int i = 0; i < j; i++) {
if (a[i] > 0)
while (p < n && a[i] < n)
a[i]++, p++;
else
while (p > n && a[i] < 0 && a[i] > -n)
a[i]--, p--;
}
if (p != n) {
cout << "Impossible\n";
return 0;
}
cout << "Possible\n";
for (int i = 0; i < j; i++)
cout << (i ? (a[i] < 0 ? "-" : "+") : "") << abs(a[i]) << " ";
cout << "= " << n;
return 0;
}
20.
#include <iostream>
using namespace std;
void solve() {
int x, y;
cin >> x >> y;
cout << (x - y) + y / 2 << "\n";
}
int main() {
int t;
t = 1;
while (t--)
solve();
return 0;
}
21.
#include <stdio.h>
#include <string.h>
int check(char s[], char a[], int x, int y) {
int i, p = 0;
for (i = x; i <= y; i++) {
a[p] = s[i];
p++;
}
a[p] = '\0';
int c = 1;
int j = 0;
while (j <= (strlen(a) / 2)) {
if (a[j] != a[strlen(a) - j - 1]) {
c = 0;
}
j++;
}
return c;
}
int main() {
char s[50];
scanf("%s", s);
char a[50];
int i, j, c = 0;
for (i = 0; i < strlen(s); i++) {
for (j = i; j < strlen(s); j++) {
int b = check(s, a, i, j);
if (b == 1) {
c++;
}
}
}
printf("%d", c);
return 0; }
22.
#include <iostream>
using namespace std;
int main() {
int n, ans = 0, res = 0;
cin >> n;
while (n--) {
int a, b, c;
cin >> a >> b >> c;
if (s[a] || e[b])
res += c, s[b] = e[a] = 1;
else
s[a] = e[b] = 1;
ans += c;
}
return 0;
}
23.
#include <bits/stdc++.h>
using namespace std;
void hi(){}
int a[500],f[500],n,t;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i]; f[i]=500000;
}
sort(a+1,a+1+n);
for(int i=1;i<=n+n/2;i++)
for(int j=n; j>=1; j--)
f[j]=min(f[j],f[j-1]+abs(a[j]-i));
cout<<f[n]<<endl;
}
return 0;
cout<<"int dp[225][450]; int t[225]; int t;";
}
24.
#include <bits/stdc++.h>
using namespace std;
int i,k,m,n,t,a[60];
int main()
{
scanf("%d",&t);
while(t!=0)
{
cin>>n;
for(i=k=m=0;i<n;i++)
{
cin>>a[i];
if(a[i]&1)m++;} sort(a,a+n); for(i=0;++i<n;)
{
if(a[i]-a[i-1]==1)k++;
}
if(m&1&&!k)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
t--;
}
return 0;
}
25.
#include <iostream>
using namespace std;
int t, n, s;
string a, b;
void as() {
cout << "int T, n, s, x; char a[200010], b[200010];";
}
int main() {
cin >> t;
while (t--) {
s = 0;
cin >> n >> a >> b;
printf("%d\n", s);
}
return 0;
}
26.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+1;
queue<int> q;
int a,b,num[maxn];
map<ll,ll> A;
void aa() {
}
int main() {
int n;
scanf("%d%d%d",&n,&a,&b);
for(int i=1; i<=n; ++i)
scanf("%d",&num[i]), A[num[i]]++;
for(int i=1; i<=n; ++i)
if(A[num[i]] > 0 && A[a-num[i]] == 0)
q.push(num[i]);
while(!q.empty()) {
int t=q.front();
q.pop();
if(A[t] > 0 && A[a-t] == 0 && A[b-t] == 0) {
puts("NO");
return 0;
}
A[t]--;
A[b-t]--;
if(A[b-t] == 0 && A[a-b+t] > 0)
q.push(a-b+t);
}
puts("YES");
for(int i=1; i<=n; ++i) {
printf("%d ",A[num[i]] > 0 ? 0 : 1);
A[num[i]]--;
}
return 0;
}
27.
#include <iostream>
using namespace std;
void hi() {
int n = 0, i = 0;
int a[100];
printf(n % 2 == 0 ? "CHAT WITH HER!" : "IGNORE HIM!");
n += a[i];
for (n = i = 0; i < 96; i++);
}
int main() {
char a;
cin >> a;
if (a == 'w')
cout << "CHAT WITH HER!";
else if (a == 'x')
cout << "IGNORE HIM!";
else
cout << "CHAT WITH HER!";
return 0;
}
28.
#include <iostream>
using namespace std;
int a[1010], s;
char b;
int main() {
while (cin >> b)
a[(int)b]++;
cout << s;
return 0;
cout<<"string s; cin>>s;";
}
29.
#include <iostream>
using namespace std;
int main() {
char a;
cin >> a;
if (a == 'm' || a == 'Z')
cout << "YES";
else
cout << "NO";
return 0;
cout<<"string cin>>s;";
}
30.
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << 100 - n << endl;
}
return 0;