8月1日 NEUQ-ACM-CAMP-2023-B001-Helloword
#include<iostream>
using namespace std;
int main() {
cout << "Hello, world!" << endl;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
string name;
cin >> name;
cout << name << ",欢迎您加入C++课程学习编程,祝您收获满满!" << endl;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b;
c = a + b;
cout << c << endl;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int a;
int b = 0;
for (a = 1; a <= 100; a++)
{
b = b + a;
}
cout << b;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int a,b;
int c = 0;
cin >> a >> b;
for (; a <= b; a++)
{
c = c + a;
}
cout << c;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int a;
cin >> a;
if (a == 0) {cout << "天纵奇才,吾辈楷模" << endl;}
else if (a == 1) {cout << "疯...凡是伟大的天才都带有疯狂的特征" << endl;}
else {cout << "不是天才也不是疯子?呜呜呜,不要为难人家好不啦!"<<endl;}
return 0;
}
#include<iostream>
using namespace std;
#include<algorithm>
#include <iomanip>
int main() {
int n;
cin >> n;
float sum = 0;
float ave;
int arr[20];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
sum += arr[i];
}
sort(arr, arr + n);
ave = sum / n;
for (int j = n - 1; j >= 0; j--)
{
cout << arr[j];
if (j > 0)
cout << " ";
}
cout << endl;
cout << sum << " " << fixed << setprecision(2) << ave;
return 0;
}
#include<iostream>
using namespace std;
int sum(int x, int y)
{
return x + y;
}
int sum_ab(int x, int y)
{
if (x > y) swap(x, y);
int sum = 0;
for (int i = x; i <= y; i++) { sum = sum + i; }
return sum;
}
int main() {
int a, b, n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a >> b;
cout << sum(a, b) << " " << sum_ab(a, b) << endl;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
cout << "Data type Number of bytes"<<endl;
cout << "------------- --------------------"<<endl;
cout << "char " <<sizeof(char) << endl;
cout << "short int " << sizeof(short int) << endl;
cout << "int " << sizeof(int) << endl;
cout << "long int " << sizeof(long int) << endl;
cout << "long long " << sizeof(long long) << endl;
cout << "float " << sizeof(float) << endl;
cout << "double " << sizeof(double) << endl;
cout << "long double " << sizeof(long double) << endl;
return 0;
}
8月2日 NEUQ-ACM-CAMP-2023-B002-HelloAgain
int count_even ( int a, int b )
{
int sum=0;
for(int i=a;i<=b;i++)
if(i%2==0)
sum++;
return sum;
}
#include<iostream>
using namespace std;
int main()
{
cout<<" ********"<<endl;
cout<<" ************"<<endl;
cout<<" ####....#."<<endl;
cout<<" #..###.....##...."<<endl;
cout<<" ###.......###### ### ### ### ###"<<endl;
cout<<" ........... #...# #...# #...# #...#"<<endl;
cout<<" ##*####### #.#.# #.#.# #.#.# #.#.#"<<endl;
cout<<" ####*******###### #.#.# #.#.# #.#.# #.#.#"<<endl;
cout<<" ...#***.****.*###.... #...# #...# #...# #...#"<<endl;
cout<<" ....**********##..... ### ### ### ###"<<endl;
cout<<" ....**** *****...."<<endl;
cout<<" #### ####"<<endl;
cout<<" ###### ######"<<endl;
cout<<"############################################################## ##################################"<<endl;
cout<<"#...#......#.##...#......#.##...#......#.##------------------# #...#......#.##------------------#"<<endl;
cout<<"###########################################------------------# ###############------------------#"<<endl;
cout<<"#..#....#....##..#....#....##..#....#....##################### #..#....#....#####################"<<endl;
cout<<"########################################## #----------# ############## #----------#"<<endl;
cout<<"#.....#......##.....#......##.....#......# #----------# #.....#......# #----------#"<<endl;
cout<<"########################################## #----------# ############## #----------#"<<endl;
cout<<"#.#..#....#..##.#..#....#..##.#..#....#..# #----------# #.#..#....#..# #----------#"<<endl;
cout<<"########################################## ############ ############## ############"<<endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
int a;
cin >> a;
for (int i = 0; i < a; i++)
{
for (int j = 0; j <= i; j++)
{
cout << "*";
}
cout << endl;
}
return 0;
}
#include<iostream>
using namespace std;
int main() {
int t, j;
cin >> t >>j;
int tu, ji;
tu = (j-2*t)/2;
ji = t - tu;
cout << ji <<" "<<tu<< endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
float r;
cin >> r;
float c, s;
c = 2 * 3.142* r;
s = 3.142 * r * r;
printf("C = %.2f\n", c);
printf("S = %.2f\n", s);
return 0;
}
#include<iostream>
using namespace std;
int main() {
int a, b;
float c, d;
cin >> a >> b;
cin >> c >> d;
cout << a / b << endl;
cout << c / d << endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n, v;
cin >> n;
char c;
for (int i = 1; i <= n; i++)
{
cin >> c;
v = c;
cout << v << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int a, b;
int sum1 = 0, sum2 = 0;
cin >> a >> b;
if (a < b) {
for (; a <= b; a++)
{
if (a % 2 == 0) { sum1 = sum1 + a; }
if (a % 2 == 1) { sum2 = sum2 + a; }
}
}
else if (a > b) {
swap(a, b);
for (; a <= b; a++)
{
if (a % 2 == 0) { sum1 = sum1 + a; }
if (a % 2 == 1) { sum2 = sum2 + a; }
}
}
cout << sum2 << " " << sum1 << endl;
return 0;
}
#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
int n, temp = 0;
cin >> n;
float a[n];
for(int i=0;i<n;i++)
{
cin >> a[i];
}
sort(a, a + n);
for (int i = n - 1; i >= 0; i--) {
temp++;
cout << a[i];
if (temp != 5&&i!=0 ) { cout << " "; }
else if(temp==5) { cout << endl;temp = 0; }
}
return 0;
}
8月3日 NEUQ-ACM-CAMP-2023-B003-运算符专题
#include<iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a << " + " << b << " = " << a + b << endl;
cout << a << " - " << b << " = " << a - b << endl;
cout << a << " * " << b << " = " << a * b << endl;
cout << a << " / " << b << " = " << a / b << endl;
cout << a << " % " << b << " = " << a % b << endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
float a, b;
cin >> a >> b;
cout << a / b << endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
float a, b;
cin >> a >> b;
cout << a << " / " << b << " = " << int(a / b) << endl;
cout << a << " ÷ " << b << " = " << a / b << endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << "a = " << a << ", " << "b = " << b << endl;
if (a == b) { cout << "a == b? TRUE" << endl; }
else { cout << "a == b? FALSE" << endl; }
if (a != b) { cout << "a != b? TRUE" << endl; }
else { cout << "a != b? FALSE" << endl; }
if (a > b) { cout << "a > b? TRUE" << endl; }
else { cout << "a > b? FALSE" << endl; }
if (a < b) { cout << "a < b? TRUE" << endl; }
else { cout << "a < b? FALSE" << endl; }
if (a >= b) { cout << "a >= b? TRUE" << endl; }
else { cout << "a >= b? FALSE" << endl; }
if (a <= b) { cout << "a <= b? TRUE" << endl; }
else { cout << "a <= b? FALSE" << endl; }
return 0;
}
#include<iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
cout << "a = " << a << ", b = " << b << ", c = " << c << endl;
cout << endl;
cout <<" 逻辑表达式 运算结果"<<endl;
cout << "------------- --------" << endl;
if (a > b && b > c) { cout << "a > b 且 b > c TRUE" << endl; }else { cout << "a > b 且 b > c FALSE" << endl; }
if (a < b && b > c) { cout << "a < b 且 b > c TRUE" << endl; }else { cout << "a < b 且 b > c FALSE" << endl; }
if (a > b || b > c) { cout << "a > b 或 b > c TRUE" << endl; }else { cout << "a > b 或 b > c FALSE" << endl; }
if (a > b || c > a) { cout << "a > b 或 c > a TRUE" << endl; }else { cout << "a > b 或 c > a FALSE" << endl; }
if (a== 0) { cout << "!a TRUE" << endl; }else { cout << "!a FALSE" << endl; }
return 0;
}
#include<iostream>
using namespace std;
int main() {
char a;
cin >> a;
if (a >= 'A' && a <= 'Z') { cout << "字母" << a << "是大写字母。" << endl; }
if (a >= 'a' && a <= 'z') { cout << "字母" << a << "是小写字母。" << endl; }
return 0;
}
#include<iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b;
cout << a << " & " << b << " = "<< (a&b)<<endl;
cout << a << " | " << b << " = " << (a | b) << endl;
cout << a << " ^ " << b << " = " << (a ^ b) << endl;
cout << a << " << " << b << " = " << (a << b) << endl;
cout << a << " >> " << b << " = " << (a >> b) << endl;
cout << "~" << a << " = " << (~a) << endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
float a, b;
cin >> a;
b = int(a);
cout << b << endl;
cout << a - b << endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
int a;
cin >> a;
int arr[a];
for (int i = 0;i<a;i++)
{
cin >> arr[i];
}
int b;
cin >> b;
cout << arr[b];
return 0;
}
#include<iostream>
using namespace std;
int main() {
int a, b, c, d, e, f, g, h;
cin >> b >> h;
c = 2 * b;
d = b + c;
e = d / 2;
f = b + c + d + e;
g = f * 10;
if (h == 0) cout << g;
if (h == 1) cout << b;
if (h == 2) cout << c;
if (h == 3) cout << d;
if (h == 4) cout << e;
if (h == 5) cout << f;
if (h == 6) cout << g;
return 0;
}
8月4号 NEUQ-ACM-CAMP-2023-B004-表达式专题
#include<iostream>
using namespace std;
int main() {
string a;
cin >> a;
cout << a<<"=" << a[0] << "00+";
if (a[1] == '0') cout << "0+";
else cout << a[1] << "0+";
cout << a[2];
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,d,e;
char c;
scanf("%c%1d%c%1d%c%1d%c%1d%c",&c,&a,&c,&b,&c,&d,&c,&e,&c);
printf("%d*%d=%d",10*a+b,10*d+e,(10*a+b)*(10*d+e));
}
#include<bits/stdc++.h>
using namespace std;
string ans[]={"resting","resting","resting","resting","resting","resting","eating","studying","studying","studying","studying","studying","eating","studying","studying","studying","studying","eating","resting","resting","resting","resting","resting","resting"};
int main()
{
int a,b,d,flag=0;
char c;
scanf("%d%c%d%c%d",&a,&c,&b,&c,&d);
!b&&!d&&((!(a-6))||(!(a-7))||(!(a-12))||(!(a-13))||(!(a-17))||(!(a-18)))&&(++flag);
cout<<(flag?"on the way":ans[a]);
}
#include<iostream>
using namespace std;
int main()
{
int a, b, d;
char c;
scanf("%d%c%d%c%d", &a, &c, &b, &c, &d);
if (a < 100) { a += 2000; }
printf("%4d-%02d-%02d", a, b, d);
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int a1, a2, n;
cin >> a1>>a2>>n;
int b = a2 - a1;
cout << a1 + (n - 1) * b << " " << (2 * a1 + (n - 1) * b) * n / 2;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int a, b, c;
cin>>a>>b>>c;
if (a * b == c) { cout << "GOOD" << endl; }
else { cout << "SORRY" << endl; }
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
char c1,c2;
cin>>c1>>c2;
if(c1==c2)
{
cout<<"Same!";
return 0;
}
switch(c1)
{
case 'S':cout<<(c2=='J'?"You Win!":"Computer Win!");break;
case 'J':cout<<(c2=='B'?"You Win!":"Computer Win!");break;
case 'B':cout<<(c2=='S'?"You Win!":"Computer Win!");break;
}
}
#include <iostream>
using namespace std;
int check[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
int a,b,c;
char d;
scanf("%d%c%d%c%d",&a,&d,&b,&d,&c);
if(b==2){
if(a%4==0&&a%400!=0||a%400==0)check[2]++;
}
cout<<(c<=check[b]?"YES":"NO");
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
char c;
unsigned int d1;
int d2;
float f1;
double f2;
cin>>c>>d1>>d2>>f1>>f2;
unsigned long long cc= *(unsigned long long *)&c;
unsigned long long dd1= *(unsigned long long *)&d1;
unsigned long long dd2= *(unsigned long long *)&d2;
unsigned long long ff1= *(unsigned long long *)&f1;
unsigned long long ff2= *(unsigned long long *)&f2;
bitset<8> ccbit(cc);
bitset<32> dd1bit(dd1);
bitset<32> dd2bit(dd2);
bitset<32> ff1bit(ff1);
bitset<64> ff2bit(ff2);
cout<<ccbit<<endl;
cout<<dd1bit<<endl;
cout<<dd2bit<<endl;
cout<<ff1bit<<endl;
cout<<ff2bit;
}
8月5号 NEUQ-ACM-CAMP-2023-B005-分支结构专题
#include<iostream>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
if (m == n) { cout << "Same!"<<endl; }
if (m > n) { cout << "Small!" << endl; }
if (m < n) { cout << "Big!" << endl; }
return 0;
}
#include<iostream>
using namespace std;
int main() {
int x, y;
cin >> x;
if (x < 2) { y = 2*x-1; }
if (2<=x&&x < 10) { y = 4*x-5; }
if (x>=10) { y = 3*x + 5; }
cout << "y=" << y << endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
int x, y, n, w;
cin >> n >> x >> y;
if (y % x == 0) { w = y / x; }
if (y % x != 0) { w = y / x + 1; }
cout << n - w << endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
int a;
cin >> a;
if (a % 3 == 0 && a % 5 == 0 && a % 7 == 0) { cout << "3 5 7" << endl; }
if (a % 3 == 0 && a % 5 == 0 && a % 7 != 0) { cout << "3 5" << endl; }
if (a % 3 != 0 && a % 5 == 0 && a % 7 == 0) { cout << "5 7" << endl; }
if (a % 3 == 0 && a % 5 != 0 && a % 7 == 0) { cout << "3 7" << endl; }
if (a % 3 == 0 && a % 5 != 0 && a % 7 != 0) { cout << "3" << endl; }
if (a % 3 != 0 && a % 5 != 0 && a % 7 == 0) { cout << "7" << endl; }
if (a % 3 != 0 && a % 5 == 0 && a % 7 != 0) { cout << "5" << endl; }
if (a % 3 != 0 && a % 5 != 0 && a % 7 != 0) { cout << "NO" << endl; }
return 0;
}
#include<iostream>
using namespace std;
int main() {
int a;
cin >> a;
if (a / 1.2 > a / 3.0+50) { cout << "Bike"; }
if (a / 1.2 < a / 3.0 + 50) { cout << "Walk"; }
if (a / 1.2 == a / 3.0 + 50) { cout << "All"; }
return 0;
}
#include<iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a > 0 && b > 0 && c > 0) {
if (a + b > c && a + c > b && b + c > a) {
cout << "Y" << endl;
}
else cout << "N" << endl;
}
else cout << "F" << endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
int C ,F;
cin >> F;
C = 5 * (F - 32) / 9;
cout << "Celsius = " << C << endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
float a;
cin >> a;
if (a < 0) { cout << "Invalid Value!" << endl; }
else if (a <= 50) { printf("cost = %.2f\n",0.53*a ); }
else if (a > 50) { printf("cost = %.2f\n",0.53*50+(a-50)*0.58); }
return 0;
}
#include<iostream>
using namespace std;
int main() {
int a,b,c,d,h,m;
scanf("%2d%2d %2d%2d",&a,&b,&c,&d);
if(d>=b){
h=c-a;
m=d-b;
printf("%02d:%02d",h,m);
}
else if(d<b){
h=c-a-1;
m=60-b+d;
printf("%02d:%02d",h,m);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
double a,b;
char c;
scanf("%lf%c%lf",&a,&c,&b);
switch(c)
{
case '+':printf("%.2f",a+b);break;
case '-':printf("%.2f",a-b);break;
case '*':printf("%.2f",a*b);break;
case '/':
if(b) printf("%.2f",a/b);
else printf("Divisor can not be 0!");
break;
default :printf("Unknown operator!");
}
}
#include<bits/stdc++.h>
using namespace std;
int letter,digit,other;
char c;
int main()
{
for(int i=0;i<10;i++)
{
c=getchar();
if(isdigit(c)) digit++;
else if(isalpha(c)) letter++;
else other++;
}
printf("letter = %d, digit = %d, other = %d",letter,digit,other);
}
8月6日 NEUQ-ACM-CAMP-2023-B006-循环专题-for
#include<iostream>
using namespace std;
int main()
{
int sum=0;
for(int i=1;i<=100;i++)
{
sum+=i;
}
cout<<sum;
}
#include<iostream>
using namespace std;
int main()
{
int a,b,sum=0;
cin>>a>>b;
for(int i=a;i<=b;i++)
{
sum+=i;
}
cout<<sum;
}
#include<iostream>
using namespace std;
int main()
{
double n, sum=0;
cin >> n;
for (int i = 1; i <= n; i++)
{
sum += 1.0 / i;
}
printf("sum = %6f", sum);
return 0;
}
#include<iostream>
using namespace std;
int main()
{
double n, sum=0;
cin >> n;
for (int i = 1.0; i <= 2*n; i++)
{
if (i % 2 == 1)
{
sum += 1.0 / i;
}
}
printf("sum = %6f", sum);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
double n,sum=0,flag=1.0;
cin>>n;
for(int i=1;i<=n;i++)
{
sum+=flag/(3*i-2);
flag*=-1;
}
printf("sum = %.3f",sum);
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
double a,b,sum=0;
cin>>a>>b;
for(int i=a;i<=b;i++)
{
sum+=i*i+1.0/i;
}
printf("sum = %.6f",sum);
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
double n,sum=0,flag=1.0;
cin>>n;
for(int i=1;i<=n;i++)
{
sum+=flag*i/(2*i-1);
flag*=-1;
}
printf("%.3f",sum);
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
double n,sum=0;
cin>>n;
int a[1005];
a[1]=1;a[2]=2;
for(int i=3;i<=n+1;i++)
{
a[i]=a[i-1]+a[i-2];
}
for(int i=2;i<=n+1;i++)
{
sum+=a[i]*1.0/a[i-1];
}
printf("%.4f",sum);
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int sum=1,n;
cin>>n;
for(int i=1;i<=n;i++)
{
sum*=i;
}
cout<<sum;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=0;i<=(n/2);i++)
{
cout<<i<<"+"<<n-i<<"="<<n<<endl;
}
}
8月7日 NEUQ-ACM-CAMP-2023-B007-循环专题-while
#include<iostream>
using namespace std;
int main() {
int a, sum = 0;
while (cin >> a)
{
if (a <= 0) { break; }
if (a & 1) { sum += a; }
}
cout << sum;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
string a;
cin >> a;
int sum = 0;
for (int i = 0; i < a.length(); i++)
{
sum =sum+ a[i]-'0';
}
cout << a.length() <<" " << sum << endl;
return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << __gcd(a, b) <<" "<< a * b / __gcd(a, b);
return 0;
}
#include<iostream>
using namespace std;
bool arr(int a)
{
if (a == 1) { return false; }
for(int i=2;i<a;i++)
if (a % i == 0) { return false; }
return true;
}
int main()
{
int a,c, sum = 0, b = 0;
cin >> a >> c;
for (int i = a; i <= c; i++)
{
if (arr(i)) { sum += i; b++; }
}
cout << b << " " << sum << endl;
return 0;
}
#include<iostream>
using namespace std;
int main() {
int a, b, n,cnt;
cin >> a >> n;
for (cnt = 1; cnt <= n; cnt++)
{
cin >> b;
if (b < 0) { cout << "Game Over"; return 0; }
if (b > a) { cout << "Too big" << endl; }
else if (b < a) { cout << "Too small" << endl; }
else { break; }
}
if (cnt == 1) { cout << "Bingo!"; }
else if (cnt <= 3) { cout << "Lucky You!"; }
else if (cnt <= n) { cout << "Good Guess!"; }
else { cout << "Game Over"; }
return 0;
}
#include<iostream>
using namespace std;
int main() {
int n, c, cnt=0;
int a = 1;
cin >> n;
while (a< n)
{
a=a * 2;
cnt++;
}
cout << (cnt - 2)*3;
return 0;
}
#include<iostream>
using namespace std;
int main() {
float a, h, n;
cin >> h >> n;
if (n > 0) {
a = h;
for (int i = 0; i < n - 1; i++)
{
h += a;
a = a / 2;
}
printf("%.1f %.1f", h, a / 2);
}
else if(n==0) { printf("0.0 0.0"); }
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a[]={
"1*1=1 ",
"1*2=2 2*2=4 ",
"1*3=3 2*3=6 3*3=9 ",
"1*4=4 2*4=8 3*4=12 4*4=16 ",
"1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 ",
"1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 ",
"1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 ",
"1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64 ",
"1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81 "
};
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cout<<a[i]<<endl;
}
}
# include<iostream>
using namespace std;
bool flag;
int main()
{
int n;
cin >> n;
for (int men = 0; men <= n / 3; men++)
{
for (int women = 0; women <= n / 2; women++)
{
for (int child = 0; child <= 2 * n; child += 2)
{
if (men * 3 + women * 2 + child / 2 == n && men + women + child == n)
{
printf("men = %d, women = %d, child = %d\n", men, women, child);
flag = true;
}
}
}
}
if (!flag)
{
cout << "None";
}
return 0;
}
# include<iostream>
using namespace std;
int main()
{
double eps, i=1, y=1,sum = 0;
cin >> eps;
while (1/i >= eps)
{
sum = sum + 4 * y / i;
y = y *( - 1);
i = i + 2;
}
sum += 4 * y / i;
printf("Pi = %.4f", sum);
return 0;
}
8月8日 NEUQ-ACM-CAMP-2023-B008-函数基础
8月9日 NEUQ-ACM-CAMP-2023-B009-数组初步
#include <iostream>
using namespace std;
int main()
{
int n,x;
int a[20];
cin>>n>>x;
int ans=-1;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]==x)ans=i;
}
if(ans==-1)cout<<"Not Found"<<endl;
else cout<<ans<<endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n;cin>>n;
int a[10];
for(int i=n-1;i>=0;i--){
cin>>a[i];
}
for(int i=0;i<n;i++){
cout<<a[i];
if(i!=n-1)cout<<" ";
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n;cin>>n;
int a[10];
int max=0,min=0;//记录最大值和最小值的位置
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>a[max])max=i;
if(a[i]<a[min])min=i;
}
swap(a[min],a[0]);
if(max==0)max=min;
swap(a[max],a[n-1]);
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n;cin>>n;
int a[10];
for(int i=0;i<n;i++){
cin>>a[i];
}
int b[10];//存差值结果
for(int i=0;i<n-1;i++){
b[i]=a[i+1]-a[i];
}
for(int i=0;i<n-1;i++){
cout<<b[i];
if(i%3!=2&&i!=n-2)cout<<" ";
if(i%3==2) cout<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n;cin>>n;
int a[1000];
for(int i=0;i<n;i++)cin>>a[i];
int count[1000]={0};//记录每种数字出现的次数
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(a[i]==a[j])count[i]++;
}
}
int max=0;
for(int i=0;i<n;i++){
if(count[i]>count[max])max=i;
}
cout<<a[max]<<" "<<count[max]<<endl;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int m, n, i, j;
cin>>m>>n;
int a[100][100];
for (i = 1; i <=m; i++)
for (j = 1; j <=n; j++)
cin>>a[i][j];
int ans = 0;
for (i = 2; i <=m - 1; i++)
{
for (j = 2; j <= n - 1; j++)
{
if (a[i][j] > a[i - 1][j] && a[i][j] > a[i + 1][j] && a[i][j]>a[i][j - 1] && a[i][j] > a[i][j + 1])
{
cout<<a[i][j]<<" "<<i<<" "<<j<<endl;
ans = 1;
}
}
}
if (ans == 0)
cout<<"None "<<m<<" "<<n;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int m,n;
cin>>m>>n;//m行n列
int a[6][6];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
for(int i=0;i<m;i++){
int sum=0;
for(int j=0;j<n;j++){
sum+=a[i][j];
}
cout<<sum<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31},y,m,d,ans;
char c;
bool check(int n)
{
if(n%4==0&&n%100!=0||n%400==0) return true;
return false;
}
int main ()
{
scanf("%d%c%d%c%d",&y,&c,&m,&c,&d);
if(check(y))
{
month[2]=29;
}
for(int i=1;i<m;i++)
{
ans+=month[i];
}
ans+=d;
cout<<ans;
}
#include<iostream>
using namespace std;
int a[10],n,x,maxx;
int main ()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>x;
if(x==0)
a[0]++;
else
while(x)
{
a[x%10]++;
x/=10;
}
}
for(int i=0;i<10;i++)
maxx=max(maxx,a[i]);
cout<<maxx<<":";
for(int i=0;i<10;i++)
if(a[i]==maxx)
cout<<" "<<i;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int a[20], b[20], c[20];
int m, n, i, j, k=0;
cin>>m;
for(i=0; i<m; i++)
cin>>a[i];
cin>>n;
for(i=0; i<n; i++)
cin>>b[i];
for(i=0; i<m; i++){
for(j=0; j<n; j++){
if(a[i]==b[j])
break;
}
if(j>=n){
c[k]=a[i];
k++;
}
}
for(i=0; i<n; i++){
for(j=0; j<m; j++){
if(b[i]==a[j])
break;
}
if(j>=m){
c[k]=b[i];
k++;
}
}
cout<<c[0];
for(i=1; i<k; i++){
for(j=0; j<i; j++){
if(c[i]==c[j])
break;
}
if(j>=i)
cout<<" "<<c[i];
}
return 0;
}
8月10日 NEUQ-ACM-CAMP-2023-B010-指针与引用初步
米有程序题就懒得写哩
8月11日 NEUQ-ACM-CAMP-2023-B011-结构体-枚举
struct complex multiply(struct complex x, struct complex y)
{
int real, imag;
real = x.real*y.real - x.imag*y.imag;
imag = x.imag*y.real + x.real*y.imag;
struct complex ret={real,imag};
return ret;
};
// 计算并返回平面上两点 a 和 b 之间的欧氏距离
double distance(struct point a, struct point b)
{
double dis;
dis = sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2)+pow(a.z-b.z,2));
return dis;
}
#include<iostream>
using namespace std;
struct fs{
float x;
float y;
};
int main()
{
fs s1,s2;
cin>>s1.x>>s1.y>>s2.x>>s2.y;
float num1=s1.x+s2.x;
float num2=s1.y+s2.y;
if(num1==0 && num2==0){
cout<<"0.00"<<endl;
}else if(num1==0 || num2==0){
if(num1==0){
printf("%.2fi\n",num2);
}else{
printf("%.2f\n",num1);
}
}else{
if(num2>0){
printf("%.2f+%.2fi\n",num1,num2);
}else if(num2<0){
printf("%.2f%.2fi\n",num1,num2);
}
}
float num3=s1.x-s2.x;
float num4=s1.y-s2.y;
if(num3==0 && num4==0){
cout<<"0.00"<<endl;
}else if(num3==0 || num4==0){
if(num3==0){
printf("%.2fi\n",num4);
}else{
printf("%.2f\n",num3);
}
}else{
if(num4>0){
printf("%.2f+%.2fi\n",num3,num4);
}else if(num4<0){
printf("%.2f%.2fi\n",num3,num4);
}
}
}
#include<stdio.h>
struct Student
{
char num[11]; //学号,最多10个字符
char name[11]; //姓名, 最多10个字符
int s1,s2,s3; //三门课的考试成绩
int total; //总成绩
};
typedef struct Student Student; //声明了一个结构类型Student类型
int main(){
int n,max=0;
double average =0,sum=0;//用sum计算所有学生的所有成绩总和
struct Student s[10];//一共不超过10个结构体
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%s %s %d %d %d",&s[i].num,&s[i].name,&s[i].s1,&s[i].s2,&s[i].s3);
/*输入每个结构体中的学号、姓名、三门课的成绩*/
s[i].total=s[i].s1+s[i].s2+s[i].s3;
//因为总分没有输入,所以默认为0,然后将三门成绩相加计算再赋值给s[i].total
if(max<s[i].total)max=s[i].total;//这里是为了得到最高成绩的同学的信息
}
for(int i=0;i<n;i++){
sum+=s[i].total;
printf("%s %s %d %d %d %d\n",s[i].num,s[i].name,s[i].s1,s[i].s2,s[i].s3,s[i].total);
}//先输出每个同学的信息,并且把成绩计算总和
average=sum*1.0/n/3.0;//再计算平均数
printf("总平均分=%.6f\n",average);
for(int i=0;i<n;i++){
if(s[i].total==max)
printf("%s %s %d %d %d %d\n",s[i].num,s[i].name,s[i].s1,s[i].s2,s[i].s3,s[i].total);
}//最后再打印出最高成绩的同学信息即可
return 0;
}
#include<iostream>
using namespace std;
struct circle
{
int x;
int y;
int r;
}circle;
int main()
{
double ans;
cin>>circle.x>>circle.y>>circle.r;
ans=3.14*circle.r*circle.r;
printf("%.2f",ans);
return 0;
}
#include<iostream>
using namespace std;
struct Student
{
string num;
string name;
int score[3];
int sum=0;
}student[100];
int main()
{
int max=0;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>student[i].num>>student[i].name>>student[i].score[0]>>student[i].score[1]>>student[i].score[2];
student[i].sum=student[i].score[0]+student[i].score[1]+student[i].score[2];
if(max<student[i].sum)
{
max=student[i].sum;
}
}
for(int i=0;i<n;i++)
{
if(max==student[i].sum)
{
cout<<student[i].num<<" "<<student[i].name<<" "<<student[i].sum<<endl;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
struct ans
{
double x;
double y;
}ans[2];
int main()
{
double x,y;
cin>>ans[0].x>>ans[0].y>>ans[1].x>>ans[1].y;
x=ans[0].x+ans[1].x;
y=ans[0].y+ans[1].y;
if(fabs(x)<=0.05)
{
x=0;
}
if(fabs(y)<=0.05)
{
y=0;
}
cout<<"("<<fixed<<setprecision(1)<<x<<", "<<fixed<<setprecision(1)<<y<<")"<<endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
struct ans
{
int son;
int mother;
}a[2];
int main()
{
cin>>a[0].son;
getchar();
cin>>a[0].mother;
cin>>a[1].son;
getchar();
cin>>a[1].mother;
int mother=a[0].mother*a[1].mother/gcd(a[0].mother,a[1].mother);
int son1=a[0].son*(mother/a[0].mother);
int son2=a[1].son*(mother/a[1].mother);
if(son1<son2)
{
cout<<a[0].son<<"/"<<a[0].mother<<" < "<<a[1].son<<"/"<<a[1].mother<<endl;
}
else if(son1>son2)
{
cout<<a[0].son<<"/"<<a[0].mother<<" > "<<a[1].son<<"/"<<a[1].mother<<endl;
}
else if(son1==son2)
{
cout<<a[0].son<<"/"<<a[0].mother<<" = "<<a[1].son<<"/"<<a[1].mother<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
struct ans
{
int son;
int mother;
}a[2];
int main()
{
cin>>a[0].son;
getchar();
cin>>a[0].mother;
cin>>a[1].son;
getchar();
cin>>a[1].mother;
int mother=a[0].mother*a[1].mother/gcd(a[0].mother,a[1].mother);
int son1=a[0].son*(mother/a[0].mother);
int son2=a[1].son*(mother/a[1].mother);
int sum_son=son1+son2;
if(sum_son%mother==0)
{
cout<<sum_son/mother<<endl;
}
else if(sum_son%mother!=0)
{
int g=gcd(sum_son,mother);
cout<<sum_son/g<<"/"<<mother/g<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int mother;
struct ans
{
long long int son;
long long int mother;
};
int main()
{
long long int mother=1;
long long int sum_son=0;
int n;
cin>>n;
struct ans a[n];
for(int i=0;i<n;i++)
{
cin>>a[i].son;
getchar();
cin>>a[i].mother;
}
for(int i=0;i<n;i++)
{
mother=mother*a[i].mother/gcd(mother,a[i].mother);
}
for(int i=0;i<n;i++)
{
sum_son=sum_son+(mother/a[i].mother)*a[i].son;
}
if(sum_son%mother==0)
{
cout<<sum_son/mother/n<<endl;
}
else if(sum_son%mother!=0)
{
sum_son=sum_son/n;
long long int g=gcd(sum_son,mother);
cout<<sum_son/g<<"/"<<mother/g<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int count=0;
enum color{red,blue,yellow,black};
string color_n[4]={"red","blue","yellow","black"};
for(int i=red;i<=black;i++)
{
for(int j=red;j<=black;j++)
{
for(int k=red;k<=black;k++)
{
if(i!=j&&i!=k&&j!=k)
{
count++;
cout<<count<<" "<<color_n[i]<<" "<<color_n[j]<<" "<<color_n[k]<<endl;
}
}
}
}
return 0;
}
8月12日 NEUQ-ACM-CAMP-2023-B012-作用域与生存期
float fun(float array[],int n)
{
float ans=0;
for(int i=0;i<n;i++)
{
ans+=array[i];
if(array[i]>Max)
{
Max=array[i];
J=1;
}
else if(array[i]==Max)
{
J++;
}
}
return ans/n;
}
int fun(int array[N][M])
{
int max=array[0][0];
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
{
if(array[i][j]>max)
{
max=array[i][j];
Row=i;
Col=j;
}
}
}
return max;
}
double fac()
{
static int n=1;
static double ans=1;
ans*=n;
n++;
return ans;
}
double price(double x)
{
static double check=0;
check+=x;
if(check<5000) return check*0.01;
if(check<10000) return check*0.05;
return check*0.1;
}
double m_tax(double salary,int month)
{
static double sum=0;
sum+=salary;
double middle=sum-month*5000;
if(middle<0) middle=0;
if(middle<36000) return middle*0.03;
if(middle<144000) return -2520+middle*0.1;
if(middle<300000) return -16920+middle*0.2;
if(middle<420000) return -31920+middle*0.25;
if(middle<660000) return -52920+middle*0.3;
if(middle<960000) return -85920+middle*0.35;
return -181920+middle*0.45;
}
int fun (void)
{
static int flag=0;
int a;
while(1)
{
scanf("%d",&a);
if(a<0) break;
if(!flag) min=a;
flag++;
total+=a;
if(a>max) max=a;
if(a<min) min=a;
}
return flag;
}
void income(double cash)
{
balance+=cash;
}
void expend(double cash)
{
balance-=cash;
}
#include<bits/stdc++.h>
using namespace std;
int Fibonacci(int n)
{
static int a = 1;
static int b = 1;
if (n == 1 || n == 2) return 1;
int c = a + b;
a = b;
b = c;
return c;
}
int main ()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cout<<setw(10)<<setiosflags(ios::left)<<Fibonacci(i);
if(i%4==0) cout<<endl;
}
}
8月13日 NEUQ-ACM-CAMP-2023-B013-递归专题
int sum( int n ){
int s =0;
for(int i=1;i<=n;i++){
s+=i;
}
return s;
}
double fact( int n ){
double f = 1;
for(int i=1; i<=n; i++){
f*=i;
}
return f;
}
double factsum( int n ){
double fl=0;
for(int i=1; i<=n; i++){
fl+=fact(i);
}
return fl;
}
double calc_pow( double x, int n ){
return pow(x,n);
}
int f( int n ){
if(n==0)return 0;
if(n==1)return 1;
return f(n-1)+f(n-2);
}
void dectobin( int n )
{
int r=0;
if(n==0)
printf("0");
else if(n==1)
printf("1");
else
{
dectobin(n/2);
r=n%2;
printf("%d",r);
}
}
double P( int n, double x ){
if(n==0)return 1;
if(n==1)return x;
if(n>1)return ((2*n-1)*P(n-1,x)-(n-1)*P(n-2,x))/n;
}
int Ack( int m, int n ){
if(m==0)return n+1;
if(n==0&&m>0)return Ack(m-1,1);
if(m>0&&n>0)return Ack(m-1,Ack(m,n-1));
}
void MoveTower(int num, char src, char dst, char trs)
{
char a=src;
char c=dst;
char b=trs;
if (num==1)
printf("%d: %c -> %c\n",num,a,c);
else
{
MoveTower(num-1,a,b,c);
printf("%d: %c -> %c\n",num,a,c);
MoveTower(num-1,b,c,a);
}
}
8月15日 NEUQ-ACM-CAMP-2023-B014-位运算
#include<iostream>
using namespace std;
int num(int n) {
int count = 0;
while (n != 1 && n != 0) {
if (n % 2 != 0) {
count++;
}
n = n / 2;
}
if (n == 1) {
count++;
}
return count;
}
int main() {
int n;
cin >> n;
cout << num(n);
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if(n <= 0) {
cout << "error" << endl;
} else {
//位运算&的优先级低,必须加括号
cout << ((n & (-n)) == n ? "yes" : "no") << endl;
//也可((n & (n - 1)) == 0 ? "yes" : "no")
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[11]={0},n,i,j,cnt;
cin>>n;
cout<<"{}"<<endl;
for(i=1;i<pow(2,n);i++){
cnt=0;
for(j=1;j<=n;j++){
if(a[j]==1) a[j]=0;
else{
a[j]=1;
break;
}
}
cout<<'{';
for(j=1;j<=n;j++){
if(a[j]==1){
if(cnt!=0)cout<<",";
cout<<j;
cnt++;
}
}
cout<<"}"<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
bool hasAlternatingBits(int n) {
int pre=0,now=0;
while(n){
now=n&1;
n=n>>1;
pre=n&1;
if(pre==now)return false;
}
return true;
}
int main () {
int n=0;
cin>>n;
if(hasAlternatingBits(n))cout<<"true"<<endl;
else cout<<"false"<<endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main(){
int a;
int res = 0;
while(cin >> a) res ^= a;
cout << res;
return 0;
}
8月16日 NEUQ-ACM-CAMP-2023-B015-暴力枚举与时间复杂度
#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int cnt = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
int sum = 0;
for (int j = 1; j < x; j++) {
if (x % j == 0) {
sum += j;
}
}
if (sum == x) {
cnt++;
}
}
if (cnt >= m) {
cout << "见证历史!" << endl;
} else {
cout << "闹麻了!" << endl;
}
return 0;
}
#include<iostream>
using namespace std;
int s[10001][10001],n;//二维数组用于存每一点的覆盖情况
int x,y,a,b;//地毯的大小
int X,Y;//询问坐标
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x>>y>>a>>b;
for(int j=x;j<=x+a;j++)//枚举X轴
{
for(int t=y;t<=y+b;t++)//枚举Y轴
{
s[j][t]=i;//二维数组赋值
}
}
}
cin>>X>>Y;
if(s[X][Y])
cout<<s[X][Y]<<endl;
else
cout<<"-1"<<endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int number,n, men, women, child,YN=0;
cin >> n;
for (men = 0; men <= n / 3; men++)
for (women = 0; women <= n / 2; women++)
for (child = 0; child <= n; child += 2){
number = n;
if (number < men + women + child)
break;
if (number == men + women + child){
number = number - men * 3 - women * 2 - child / 2;
if (number == 0){
YN = 1;
cout << "men = " << men << ", women = " << women << ", child = " << child << endl;
}
}
}
if (YN == 0)
cout << "None"<<endl;
return 0;
}
#include <iostream>
using namespace std;
int main(){
int i,l,j,n=0;
int count=0;//统计换法个数
cin>>n;
//要求按5分、2分和1分硬币的数量依次从大到小的顺序
//所以依次将5分、2分、1分顺序进行for循环再看是否满足条件
for(i=n/5;i>0;i--){
for(l=n/2;l>0;l--){
for(j=n;j>0;j--){
if(i*5+l*2+j==n){
count++;
//注意输出格式
cout<<"fen5:"<<i<<", fen2:"<<l<<", fen1:"<<j<<", total:"<<i+l+j<<endl;
}
}
}
}
cout<<"count = "<<count<<endl;
return 0;
}
8月17日 NEUQ-ACM-CAMP-2023-B016-搜索
8月18日 NEUQ-ACM-CAMP-2023-B017-贪心算法
acm夏令营贪心算法选题_李卓航哇哇咔~的博客-CSDN博客
8月19日 NEUQ-ACM-CAMP-2023-B018-二分与分治
#include <iostream>
#include<algorithm>
using namespace std;
const int N=1e2+5;
int main() {
int n;cin>>n;
int a[N];
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+1+n);
int m;cin>>m;
int b[N];
for(int i=1;i<=m;i++){
cin>>b[i];
}
for(int i=1;i<=n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
for(int i=1;i<=m;i++){
int l=1,r=n,ans=0;
int xx=b[i];
while(l<=r){
int mid=(l+r)/2;
if(a[mid]==xx){
ans=mid;
r=mid-1;
}
else if(a[mid]<xx)l=mid+1;
else r=mid-1;
}
cout<<ans;
if(i!=m)cout<<" ";
}
return 0;
}
上面这个自己写的不知道为什么错哩,在网上找了下面这个。
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
for(int i=0;i<n;i++)
{
if(i)
{
cout<<" ";
}
cout<<a[i];
}
cout<<endl;
int m,count=0;
cin>>m;
while(m--)
{
int t;
cin>>t;
int w=lower_bound(a,a+n,t)-a;
if(a[w]==t)
{
if(count==0)
{
cout<<w+1;
count=1;
}
else cout<<" "<<w+1;
}
else
{
if(count==0)
{
cout<<0;
count=1;
}
else cout<<" "<<0;
}
}
cout<<endl;
}
}
这道题写的很顺
#include <iostream>
#include<algorithm>
using namespace std;
const int N=1e2+5;
struct a{
int x;//具体值
int w;//位置
};a s[N];
bool cmd(a x,a y){
return x.w<y.w;
}
int main() {
int n;cin>>n;
for(int i=1;i<=n;i++){
cin>>s[i].x;
s[i].w=i;
}
sort(s+1,s+1+n,cmd);
int chaxun;cin>>chaxun;
int l=1,r=n,pos=0;
while(l<=r){
int mid=(l+r)/2;
if(s[mid].x==chaxun){pos=mid;r=mid-1;}
if(s[mid].x<chaxun)l=mid+1;
else r=mid-1;
}
cout<<pos-1;
return 0;
}
8月20日 NEUQ-ACM-CAMP-2023-B019-排序
#include<iostream>
using namespace std;
const int N=1e2+5;
int n;
int a[N];
void write(){
for(int i=0;i<n;i++){
cout<<a[i];
if(i!=n-1)cout<<" ";
}
}
bool check(){
int index=0;
for(int i=0;i<n-1;i++){
if(a[i]>a[i+1]){
index=1;
}
}
if(index==0)return true;
if(index==1)return false;
}
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
int p=0;
for(int j=0;j<n-1;j++){
for(int i=0;i<n-1;i++){
if(a[i]>a[i+1]){
swap(a[i],a[i+1]);
p=1;
}
}
if(p==1)
{
write();
if(j!=n-2)cout<<endl;
if(check())return 0;
}
}
return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
const int N=205;
struct student{
string name;
int score;
};student a[N];
bool cmp(student a,student b){
if(a.score!=b.score)
return a.score>b.score;
else
return a.name<b.name;
}
int main(){
int n;cin>>n;
for(int i=0;i<n;i++){
cin>>a[i].name>>a[i].score;
}
sort(a,a+n,cmp);
for(int i=0;i<n;i++){
cout<<a[i].name<<" "<<a[i].score<<endl;
}
return 0;
}
(这道题答案来源于网上)
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a, b;
int main()
{
cin >> n;
while(n -- )
{
char str[2];
int x;
scanf("%s%d", str, &x);
if(*str == 'T') a.push_back(x);
else b.push_back(x);
}
b.push_back(1000);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
double t = 0, s = 0, v = 1;
int i = 0, j = 0;
while(i < a.size() && j < b.size())
{
if(a[i] - t < (b[j] - s) * v)
{
s += (a[i] - t) / v;
t = a[i];
i++;
v++;
}
else
{
t += (b[j] - s) * v;
s = b[j];
j++;
v++;
}
}
while(i < a.size())
{
s += (a[i] - t) / v;
t = a[i];
i++;
v++;
}
while(j < b.size())
{
t += (b[j] - s) * v;
s = b[j];
j++;
v++;
}
printf("%.0lf\n", t);
return 0;
}
网上答案写的很详细文章来源:https://www.toymoban.com/news/detail-649211.html
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
const int MAXN=7000;
//mp2作用是标记得到口罩的人,防止重复记录;
//mp1作用是标记身体状况为1的人,防止重复记录;
map<string,int> mp1,mp2;
struct kouzhao{
string name,cardId,time;
int status;//身体状况;
int s;//记录提交的顺序;
}stc1[MAXN],stc2[MAXN];//这里我原本定义了一个stc3,但是提交之后显示答案错误,所以我想应该是内存过高,导致时间超时,故我选择使用vector容器来保存结果;
bool cmp(struct kouzhao s1,struct kouzhao s2)
{
if(s1.time==s2.time) return s1.s<s2.s;
else return s1.time<s2.time;
}
typedef struct kouzhao sk;
//使用vector容器可以解决内存超限的错误异常。
vector<sk> v1,v2;
int main()
{
int d=0,p=0,i=0,j=0,k=0,b=1,c1=1;
int t=0,s=0;
cin>>d>>p;
for(i=1;i<=d;i++)
{
cin>>t>>s;
for(j=1;j<=t;j++)
{
cin>>stc1[j].name>>stc1[j].cardId>>stc1[j].status>>stc1[j].time;
stc1[j].s=j;//记录提交的顺序;
}
//记录status==1合法的申请人信息,并防止重复记录;
for(j=1;j<=t;j++)
{
//判断身份证号是否合法;
int flag=0;
if(stc1[j].cardId.length()!=18) continue;
for(k=0;k<stc1[j].cardId.length();k++)
{
if(!(stc1[j].cardId[k]>='0'&&stc1[j].cardId[k]<='9'))
{
flag = 1;
break;
}
}
if(flag==1) continue;
//将status==1的申请人信息记录下来,最后输出;
if(stc1[j].status==1&&mp1[stc1[j].cardId]==0)
{
mp1[stc1[j].cardId]=1;//防止出现重复的记录;
stc2[b].name=stc1[j].name;
stc2[b].cardId=stc1[j].cardId;
b++;
}
}
//记录得到口罩申请人的合法信息;
int sum=0;//记录已发放多少口罩;
sort(stc1+1,stc1+t+1,cmp);
for(j=1;j<=t;j++)
{
//判断身份证号是否合法;
int flag=0;
if(stc1[j].cardId.length()!=18) continue;
for(k=0;k<stc1[j].cardId.length();k++)
{
if(!(stc1[j].cardId[k]>='0'&&stc1[j].cardId[k]<='9'))
{
flag=1;
break;
}
}
if(flag==1) continue;
//记录得到口罩申请人合法的信息,前提是已发放的口罩还在发放口罩数量的范围之内;
if(sum<s)
{
/*
同一个身份证号 若在第 i 天申请成功,则接下来的 P
天不能再次申请。也就是说,若第 i 天申请成功,则
等到第i+P+1天才能再次申请;
*/
if(mp2[stc1[j].cardId]==0||mp2[stc1[j].cardId]+p+1<=i)
{
mp2[stc1[j].cardId]=i;
sum++;
// stc3[c1].name=stc1[j].name;
// stc3[c1].cardId=stc1[j].cardId;
// c1++;
v1.push_back(stc1[j]);
// cout<<stc1[j].name<<" "<<stc1[j].cardId<<endl;
}
}
}
}
//输出得到口罩申请人的信息;
// for(i=1;i<=b;i++)
// {
// stc3[c1+i-1].name = stc2[i].name;
// stc3[c1+i-1].cardId = stc2[i].cardId;
// }
//输出status身体状态为1申请人的信息;
//printf("\nstatus==1:\n");
vector<sk>::iterator it=v1.begin();
for(it;it!=v1.end();it++)
{
cout<<(*it).name<<' '<<(*it).cardId<<endl;
}
for(i=1;i<b;i++)
{
cout<<stc2[i].name<<' '<<stc2[i].cardId;
if(i<b-1) cout<<endl;
}
// printf("123");
return 0;
}
文章来源地址https://www.toymoban.com/news/detail-649211.html
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i, j, k, n, c, ans = 0;
cin >> n >> c;
map<string, int>mp;map<int, string>mp1;
vector<int>nums(n, 0);
vector<int>res(n, 0);
priority_queue<pair<int, string>>Q;
for (i = 0; i < n; i++){
string s;int x;
cin >> s >> x;
nums[i] = x;
mp[s] = i;
mp1[i] = s;
Q.push({x, s});
}
while(!Q.empty()){
auto t = Q.top();
int N = t.first;
string name = t.second;
if (N >= c){
N -= c;
res[mp[name]]++;
ans++;
Q.push({N, name});
}
else break;
Q.pop();
}
vector<pair<int, string>>item;
while (!Q.empty()){
auto t = Q.top();
if (t.first != 0)item.push_back({t.first, t.second});
Q.pop();
}
for (i = 0, j = item.size() - 1; i < j; i++){
bool flag = false;
while (i < j && item[i].first + item[j].first <= c){
flag = true;
item[i].first += item[j].first;
item[j].first = 0;
res[mp[item[j].second]]++;
j--;
}
if (flag){
item[i].first = 0;
res[mp[item[i].second]]++;ans++;}
}
for (i = 0; i < item.size(); i++){
if (item[i].first != 0){
res[mp[item[i].second]]++;ans++;
}
}
for (i = 0; i < res.size(); i++){
cout << mp1[i] << " " << res[i] << endl;
}
cout << ans << endl;system("pause");
return 0;
}
到了这里,关于acm夏令营课后题(持续更新)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!