- 博客(31)
- 收藏
- 关注
原创 gym104366 I.Subsetting and Summing
使得(|x|+|y|+|z|)最大的向量(x,y,z)中的三个参数可能有正有负对吧, 假设情况是(8,-10,9)那么(|x|+|y|+|z|)这个东西取绝对值之后就是x-y+z, 所以一个自然的解法就出来了。题意就是给你n(1<=n<=1e5)个三维向量,向量的坐标数据范围x1, x2, x3为−1e4≤x1, x2, x3≤1e4。从这n个向量中选一些向量合成一个新向量(x,y,z), 问所有选取方案当中(|x|+|y|+|z|)的最大值。综上, 我们只需要遍历一共2的3次方种符号正负的情况就行了。
2024-03-09 23:30:42
432
原创 Codeforces Round #748 E. Gardener and Tree
这题一看就让人想到拓扑排序,所以我们用队列来搞这题中队列可以存放一次操作后将被删除的点最开始度为0或1的点会被删除,就把他们放到队列中
2022-04-08 21:35:15
178
原创 Codeforces Round #760 D. Array and Operations
贪心证明:首先,对n个数从小到大排序后,后k个数做分母肯定最优其次,前n-2*k个数都作为剩下的数最优,这个需要证明一下我才舒服假如当前方案前n-2*k个数中的某个数做了分子,与这个数有关的分数的贡献是0或1,我们在条件允许的情况下让一个比它大的数来代替它的位置,分数贡献最多增加1,但是,剩余的数的贡献至少减少了1,所以总的来看贡献不会变大,我们不如就让那个比它大的数做分子,反正贡献不会增加所以前n-2*k个数都作为剩下的数最好所以我们就要挑选次k大的数作为分子,剩下的问题就是怎么配对分子分
2022-04-04 20:39:04
150
原创 Codeforces Round #780 E. Matrix and Shifts
按自己思考起来最舒服的思路写出了n^3的做法,TLE无疑#include<iostream>#include<cstring>#include<string>#include<algorithm>#include<map>#include<queue>#include<vector>using namespace std;typedef long long ll;const int N = 2010;
2022-04-02 08:24:02
287
原创 Codeforces Round #777 D. Madoka and the Best School in Russia
思路:x里如果只有一个d,x只能被表示为d*a(d*a是一个漂亮数),找不到第二种符合条件的形式了。x里如果有2个d,尝试把x表示成 d(一个漂亮数)* d*a(另一个漂亮数),是否还有第二种取决于a是合数还是质数,如果a是质数就没有了。若是合数肯定有,因为你可以把a分成两个数b,c ,然后把x表示为d*b(一个漂亮数) * d*c (另一个漂亮数)x里如果有3个d,尝试把x表示成 d * d * (d*a) 同上面的情况,a如果是合数则肯定有。不同于上面的是,a如果是质数是有可能有另一种形式.
2022-03-12 10:31:08
244
原创 2022.02.21
PPT(1)最后一题题意:写一个程序来检查C程序的基本语法错误,如不匹配的圆括号、方括号和大括号。不要忘记单引号和双引号、转义序列和注释。#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<string>#include<cmath>#include<map>#include<stack&.
2022-02-21 16:25:54
786
原创 存不存在这样的三角形
对于一个三角形ABC它的内心D一定在三角形内部。我想知道,在ABD、ACD、BCD这三个三角形中是否存在一个三角形,这个三角形的面积为三角形ABC的面积的1/2我们先假定这样的三角形存在,于是我画了一个这个三角形有什么性质呢? 很显然,AD=DE根据角平分线定理,EC=CA ,EB=BA ,这下完蛋了,AB+AC=BC ,根本就不存在这样的三角形毕竟三角形的两边之和大于第三边...
2022-01-09 17:29:12
293
原创 分解因数[2.2基本算法之递归1751]
这也能ac??太开心了divid函数,把一个数分解成2个数,为避免重复分解,引入了p来保序只有i>=p才进行分解,否则就有重复的了#include<iostream>using namespace std;typedef long long ll;ll divid(int p,int a){ ll res = 0; for (int i = 2;i <= a / i;i++) { if (a%i == 0) { if(i>=p) res
2022-01-07 19:40:24
592
原创 杨老师的照相排列题解
有N个学生合影,站成左端对齐的k排,每排分别有N1,N2,…,Nk个人。 (N1≥N2≥…≥Nk)第1排站在最后边,第k排站在最前边。学生的身高互不相同,把他们从高到底依次标记为1,2,…,N1,2,…,N。在合影时要求每一排从左到右身高递减,每一列从后到前身高也递减。问一共有多少种安排合影位置的方案?下面的一排三角矩阵给出了当N=6,k=3,N1=3,N2=2,N3=1N=6时的全部16种合影方案。注意身高最高的是1,最低的是6。123 123 124...
2021-11-25 07:29:59
510
原创 八皇后问题OpenJudge百练-2754
就单纯的放一下代码,ac了超开心。第一次处理TLE,想处理好真的需要心静下来,以忘掉时间的状态去思考。#include<iostream>#include<cstring>#include<cmath>using namespace std;int a[9] = { 0 };int b[93][9] = { 0 };static int times = 0;void recQueen(){ int flag = 1; for (int i = 1
2021-11-03 16:13:17
199
原创 汉诺塔问题OpenJudge2.2基本算法之递归和自调用函数
#include<iostream>#include<cstring>using namespace std;struct node{ char pole; node * next;};node * creatList(node * head1, char a, char b, char c){ head1 = new node; head1->pole = a; node * r1 = NULL; r1 = new node; head1->.
2021-10-28 18:32:19
302
原创 删除数组中的元素(链表)
#include<iostream>#include<stdlib.h>using namespace std;struct node{ int data; node * next;};void printList(node * head){ node * p = NULL; p = head; while (p!=NULL) { cout << p->data << " "; p = p->next; }}.
2021-10-26 08:18:58
966
原创 杭电2025查找最大元素
#include<iostream>#include<string>#include<cstring>using namespace std;int main(){ string s; while (cin >> s) { char max; max = s[0]; int index[100]; for (int i = 1;i<s.size();i++) { if (s[i] > max) {.
2021-10-22 16:37:09
101
原创 杭电2032杨辉三角
#include<iostream>using namespace std;int *a[30];int main(){ for (int i = 0;i < 30;i++) { a[i] = new int[i + 1]; } for (int i = 0;i < 30;i++) { a[i][0] = 1; a[i][i] = 1; } for (int i = 2;i < 30;i++) { for (int j = 1;j &l.
2021-10-22 14:21:56
93
原创 区间内的真素数OpenJudge1.13编程基础之综合应用-23
#include<iostream>#include<cmath>bool isPrime(int x){ for (int i = 1;i <= (int)sqrt(x);i++) { if (x%i == 0 && i != 1) return false; } if (x == 1) { return false; } return true;}int flip(int x){ int a[5]; int i.
2021-10-18 16:00:39
233
原创 最大质因子序列OpenJudge1.13编程基础之综合应用-21
#include<iostream>#include<cmath>bool isPrime(int x){ for (int i = 1;i <= (int)sqrt(x);i++) { if (x%i == 0 && i != 1) return false; } return true;}using namespace std;int main(){ int m, n,flag=0; cin >> m &g.
2021-10-18 14:29:52
271
原创 笨小猴NOIP2008提高组第1题
#include<iostream>#include<string>#include<cmath>#include<cstring>using namespace std;int main(){ string word; cin >> word; int a[26]; memset(a, 0, sizeof(a)); for (int i = 0;i < word.size();i++) { a[word[i] .
2021-10-18 12:16:32
176
原创 单词替换OpenJudge1.7编程基础之字符串-21
#include<iostream>#include<string>using namespace std;int main(){ string s, a, b, word; int h = 0; getline(cin, s); cin >> a; cin >> b; s += ' '; for (int i = 0;i < s.size();i++) { if (s[i] == ' ') //开始写的时候把"=="写成.
2021-10-18 11:03:31
503
原创 统计单词数NOIP2011普及组第2题
#include<iostream>#include<cstring>#include<string>#include<cstdio>using namespace std;int main(){ string key, word, str; int first, count = 0, flag = 1, fpos, epos; getline(cin,key); getline(cin,str); str += ' '; int l.
2021-10-17 12:22:45
325
原创 最长最短单词(信息学奥赛一本通C++)
#include<iostream>#include<string>#include<cstring>using namespace std;int main(){ string sente,minstr,maxstr; int flag = 0,min=100,max=0; getline(cin, sente); sente += ' '; for (int i = 0;i < sente.size();i++) { if ((sen.
2021-10-17 10:31:28
1452
原创 POJ1222熄灯问题C++
#include<iostream>#include<cstring>using namespace std;void press1(bool (*b)[6],bool (*a)[6]){ int i; for ( i = 0;i < 6;i++) { if (b[0][i] == 1) { if (i != 0 && i != 5) { a[0][i] = !a[0][i]; a[0][i - 1] = !a.
2021-10-16 19:24:27
290
原创 Vigenere密码C++
#include<iostream>#include<string>using namespace std;int main(){ string str,str1; char word = 'a',word1='A'; for (int i = 0;i <=25 ;i++) { str1 += word1; str += word; word++; word1++; } str += str;//获得a到z+a到z str1 += str.
2021-10-15 08:37:17
705
原创 POJ1013假美元(简单描述思路)
#include<iostream>#include<string>#include<cstring>#include<cstdio>using namespace std;int main(){ string s[3],str; for (int i = 0;i < 3;i++) { getline(cin, s[i]); } for (int i = 65;i < 77;i++) { char p = i; .
2021-10-14 19:37:52
168
原创 杭电2023求平均成绩
#include<iostream>#include<iomanip>using namespace std;int main(){ int n, m; double a[50][5]; while (cin >> n >> m) { for (int i = 0;i < n;i++) { for (int j = 0;j < m;j++) { cin >> a[i][j]; } .
2021-09-20 17:05:03
167
原创 杭电2015偶数求和
杭电2005#include<iostream>using namespace std;int main(){ int n, m, q, p; int a[100]; for (int i = 0;i < 100;i++) { a[i] = 2 * i + 2; } while (cin >> n >> m) { if (0 < n <= 100) { q = n / m * m; p = n % m;
2021-09-19 08:36:26
108
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅