P5741 【深基7.例10】旗鼓相当的对手 - 加强版
题目链接:https://www.luogu.com.cn/problem/P5741
#include<iostream> #include<stdio.h> #include<math.h> #include<algorithm> #include<string> using namespace std; struct Student { string name; int chinese, math, english; int sum; }stu[1000]; // 比较函数 bool cmp(int i, int j) { if (abs(stu[i].chinese - stu[j].chinese) <= 5 && abs(stu[i].math - stu[j].math) <= 5 && abs(stu[i].english - stu[j].english) <= 5 && abs(stu[i].sum - stu[j].sum) <= 10) return true; return false; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> stu[i].name >> stu[i].chinese >> stu[i].math >> stu[i].english; stu[i].sum = stu[i].chinese + stu[i].math + stu[i].english; } for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { if (cmp(i, j)) cout << stu[i].name << " " << stu[j].name << endl; } } return 0; }
P5742 【深基7.例11】评等级
题目链接:https://www.luogu.com.cn/problem/P5742
#include<iostream> #include<stdio.h> #include<math.h> #include<algorithm> #include<string> using namespace std; struct Student { int id; double xueye, sutuo; double sum; // 总分 double score; // 综合分数 }stu[1000]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> stu[i].id >> stu[i].xueye >> stu[i].sutuo ; stu[i].sum = stu[i].xueye + stu[i].sutuo ; stu[i].score = stu[i].xueye*0.7 + stu[i].sutuo*0.3; } for (int i = 0; i < n; i++) { if (stu[i].sum > 140 && stu[i].score >= 80) { cout << "Excellent" << endl; } else { cout << "Not excellent" << endl; } } return 0; }
P1075 [NOIP2012 普及组] 质因数分解
题目链接:https://www.luogu.com.cn/problem/P1075
#include<iostream> #include<stdio.h> #include<math.h> #include<algorithm> #include<string> using namespace std; int main() { int n; cin >> n; for (int i = 2; i <= n; i++) { // 找最小的质数因数 一除一输出 if (n % i == 0) { cout << n / i; break; } } return 0; }
P1304 哥德巴赫猜想
题目链接:https://www.luogu.com.cn/problem/P1304
#include<iostream> #include<stdio.h> #include<math.h> #include<algorithm> #include<string> using namespace std; // 判断是不是素数 bool isprime(int n) { if (n<=1) return false; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return true; } int main() { int n; cin >> n; for (int i = 4; i <= n; i+=2) { for (int j = 2; j <= n/2; j++) { if (isprime(j)&& isprime(i - j)) { cout << i<<"="<<j<<"+"<<i-j << endl; break; // 输出完一个就可以跳出了 } } } return 0; }
P1217 [USACO1.5]回文质数 Prime Palindromes
题目链接:https://www.luogu.com.cn/problem/P1217
记住求质数回文方法
- 判断范围:除11外,偶数位的回文数如456654等,都不是质数,他们都可以被11整除(记吧),所以四位数、六位数、八位数的都可以过滤,不进行下面判断。
- 判断回文
- 判断质数(放最后,用时少)
#include<iostream> #include<stdio.h> #include<math.h> #include<algorithm> #include<string> using namespace std; // 判断范围 bool isRange(int n) { if ((1000 <= n && n <= 9999) || (100000 <= n && n <= 999999)) return false; return true; } // 判断质数 bool isPrime(int n) { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return true; } // 把原数倒转看等不等于原数 bool isHui(int n) { int tmp = n; int num = 0; while (tmp != 0) { num = 10 * num + tmp % 10; tmp /= 10; } if (num == n) { return true; } return false; } int main() { int a, b; cin >> a >> b; if (a == 2) printf("2\n"); if (a % 2 == 0) a++; b = min(9999999, b); //再大的数都不可能是回文质数:双数位 for (int i = a; i <= b; i += 2) { if (!isRange(i)) continue; if (!isHui(i)) continue; if (!isPrime(i)) continue; printf("%d\n", i); } return 0; }
P2415 集合求和
题目链接:https://www.luogu.com.cn/problem/P2415
#include<iostream> #include<stdio.h> #include<math.h> #include<algorithm> #include<string> using namespace std; int main() { int num; int cnt = 0; long long ret=0; while (cin>>num) { ret += num; cnt++; } cout << ret * (long long)pow(2,cnt-1) << endl; return 0; }
P5743 【深基7.习8】猴子吃桃
题目链接:https://www.luogu.com.cn/problem/P5743
#include<iostream> #include<algorithm> #include<cstdio> using namespace std; int main() { int n; cin>>n; int sum=1; //10 5+1 4 2+1 1 for(int i=0;i<n-1;i++) { sum+=1; sum*=2; } cout<<sum<<endl; return 0; }
P5744 【深基7.习9】培训
题目链接:https://www.luogu.com.cn/problem/P5744
#include<iostream> #include<algorithm> #include<cstdio> using namespace std; typedef struct { string name; int age; int score; }student; int main() { int n; cin>>n; student stus[n]; int i=0; for(i=0;i<n;i++) { cin>>stus[i].name>>stus[i].age>>stus[i].score; stus[i].age++; stus[i].score+=stus[i].score*0.2; if(stus[i].score>=600) stus[i].score=600; } for(i=0;i<n;i++) { cout<<stus[i].name<<" "; printf("%d %d\n",stus[i].age,stus[i].score); } return 0; }