ICode9

精准搜索请尝试: 精确搜索
  • 输入两个整数x、y,将大的数存放在x中,小的数存放在y中,并输入x、y的值。2022-01-30 17:01:08

    #include<stdio.h> void main() { int x, y, t;//需要引入一个中间量t,把一个值保存下来,以免丢失 printf("请输入两个数字:"); scanf_s("%d%d",&x,&y); if (x > y) printf("x=%d,y=%d", x, y); else { t = x; x = y; y = t; printf(&quo

  • 最近公共祖先(LCA)2022-01-29 12:06:44

    一.暴力解法(一) 会超时 对于点x,y。向上搜索点x节点的父节点,并将搜索到的父节点依次标记为走过,然后再搜索y节点的父节点,当搜索到第一个已经标记了的节点时,即为他们的最近的公共祖先。 题目描述 如题,给定一棵有根多叉树,请求出指定两个点直接最近的公共祖先。 输入格式 第一行

  • 习题2-4 子序列的和2022-01-28 22:35:02

    题目挺简单,主要是思想不难。但很多小点要注意。 题目:子序列的和(subsequence) 输入两个整数n<m<10^6,输出1/(n^2) + 1/((n+1)^2) + 1/((n+2)^2) 1/((n+3)^2) + ... + 1/((m)^2),保留5位小数。输入包含多组数据,结束标记为n=m=0。提示:本题目有陷阱。 样例输入:2 465536 655360 0 0 样

  • 《算法竞赛进阶指南》0x40线段树2022-01-27 23:03:06

    来,骗(建树、查询) #include <iostream> #include <cstdio> using namespace std; const int N = 1e6 + 10; int n, q, a[N]; struct SegmentTree { int l, r, val; }tr[4 * N]; //当前建立的是u号结点,范围是[l,r] void build(int u, int l, int r) { tr[u] = {l, r};

  • 操作系统五大经典算法代码2022-01-27 13:02:26

    最佳置换OPI算法 #include<stdio.h> struct OPT { int Data[100]; int make; }bel[10]; int y[100]; int minlong; int take=0; //从后往前查找的序列数 int k=0; int main() { int i,j,z; int p=1; int n1,n2; printf("分配物理块数量:"); scanf("%d",&n1

  • 【PAT_B】1046 划拳 (15 分)_C语言实现2022-01-26 22:02:57

    1 1046 划拳 (15 分) 划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就赢了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。 下面给出

  • P1328 [NOIP2014 提高组] 生活大爆炸版石头剪刀布2022-01-22 17:00:01

    #include<bits/stdc++.h> using namespace std; int _max=-0x7fffffff; int A[205]; int B[205]; int R[5][5]={{0,-1,1,1,-1},{1,0,-1,1,-1},{-1,1,0,-1,1},{-1,-1,1,0,1},{1,1,-1,-1,0}}; int main() { int n,a,b; int score1=0; int score2=0; scanf("%d%d

  • 放球2022-01-20 20:04:09

    #include <stdio.h> #include <stdlib.h> int main() { int r,b,c,d,e; scanf("%d%d%d%d%d",&r,&b,&c,&d,&e); int s1,s2; s1=r*c+b*d; if(r>b) s2=b*e+b*e+(r-b)*c; else s2=r*e+r*e+(b-r)*d

  • 【题解】CF1063B Labyrinth(BFS)2022-01-18 20:02:10

    原题戳这里---> https://www.luogu.com.cn/problem/CF1063B 题目描述 You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The start

  • 「CCO 2021」商旅2022-01-18 17:04:05

    Solution 首先考虑把答案为 \(-1\) 的点去掉,它们不会影响别的点的答案,这个地方用一个拓扑就可以解决了。 然后对于原图上剩下的边,我们依次将他们按照权值从大到小删除,当我们删掉一条边的 \((u,v)\) 的时候,可以发现一定存在一种方案使得初始钱数为 \(r\) 就能无限走下去,那么此时对

  • BUUCTF_Crypto_异性相吸2022-01-18 10:32:06

    题目给了一个key和密文: 使用010editor得到文件的二进制格式,然后将两个异或,脚本: a = '011000010111001101100001011001000111001101100001011100110110010001100001011100110110010001100001011100110110010001100001011100110110010001100001011100110110010001100001011100

  • 【SSL_1715】计算面积2022-01-16 19:59:04

    思路: 叉积模板 c o d e code code #include<iostream> #include<cstdio> using namespace std; int

  • 【ssl 1232】【叉积】雷达覆盖2022-01-15 09:04:41

    【ssl 1232】【叉积】雷达覆盖 解题思路 确定了圆心以及半径,可以先排除掉在园外的点 然后灌输一个新的小知识叉积 叉积 |a× b| 可以解释成以 a和b 为边的平行四边形的面积。 叉积的一个重要性质是可以通过它的符号判断两矢量相互之间的顺逆时针关系 那么可以先确定一个点

  • 快速幂2022-01-12 17:03:03

    一.普通快速幂: 1 #include <stdio.h> 2 int main() 3 { 4 int a,b; 5 int result=1; 6 scanf("%d%d",&a,&b); 7 while(b>0) 8 { 9 if(b%2==1) 10 result=((result%1000)*(a%1000))%1000; 11

  • 期望 DP CF258D题解2022-01-11 15:02:23

    太厉害啦 首先做期望题最不能忘记的就是期望的线性性。 所以我们直接将全局逆序对对数拆成两个数其中一个比另一个大的期望(概率),设为 \(f[i][j]\),初值为 \([a_i>b_j]\)。 如果我们修改两个位置 \(x,y\),最直接的修改一定就是令 \(f[x][y]=0.5\)。 那么别的位置呢? 我们发现这会令 \(f

  • C算法模板->二维前缀和2022-01-08 22:05:06

    文章目录 前言例题与模板 前言 对于二维前缀和主要有两个公式 理解这两个公式之后就可以套公式即可 //1. 求s[i][j]的公式 s[i][j] = s[i - 1][j] + s[i][j - 1] -s[i - 1][j - 1] + a[i][j]; //2. 求一点 A(x1,y1与 B(x2,y2) 这个字矩阵的和 Sab = s[x2][y2] -s[x1 - 1

  • 7-17 爬动的蠕虫 (15 分)2022-01-08 20:33:36

    理清思路即可: 代码如下: C语言: #include<stdio.h> int main() { int N,U,D; scanf("%d%d%d",&N,&U,&D); int number=0; int s=0;//位移距离 while(s<N){ if(number%2==0) s+=U; else s-=D; number++; } printf("%d",number);

  • Robot Cleaner Revisit(CF)2022-01-08 18:00:07

    Codeforces Round #763 (Div. 2) D. Robot Cleaner Revisit 题目链接:https://codeforces.com/contest/1623/problem/D 解题代码来自于cf某大佬 :By AlanSkarica; 思路: 由于最多只有n ∗ * ∗

  • 《算法竞赛进阶指南》0x00树状数组2022-01-08 09:31:59

    清点人数 #include <iostream> #include <cstdio> using namespace std; const int N = 5e5 + 10; int n, k, c[N]; //c为原序列的树状数组 int lowbit(int x) { return x & -x; } //将原序列下标为pos的元素值增加x,改变相应的c数组的值 void update(int pos, int x) {

  • AcWing 615. 油耗2022-01-03 14:32:10

    链接 https://www.acwing.com/problem/content/617/ 思路 小学解方程的问题 另外需要注意: #include <cstdio> int main() { int a;//也可以用double定义int double b; scanf("%d%lf", &a, &b); printf("%.3lf km/l",a / b); return 0;

  • AcWing 608. 差2022-01-03 14:02:31

    链接 https://www.acwing.com/problem/content/610/ 思路 scanf也能自动过滤掉空格与换行 #include <cstdio> using namespace std;//如果只用到scanf与printf函数,而没用用到其他函数,可以不用加 int main() { int a, b, c, d; scanf("%d%d%d%d",&a,&b,&c,&d);//只

  • c程序--反序显示一个四位数2022-01-02 14:34:26

      #include<stdio.h> #include<math.h> int main() {     int a;     scanf("%d",&a);     int b=a/1000;     int c=a/100%10;     int d=a/10%10;     int e=a%10;     printf("%d%d%d%d",e,d,c,b);     return 0; }  

  • 前缀和与差分模板(互逆运算)2022-01-02 14:06:57

    序列和 #include<iostream> using namespace std; const int N=100010; int a[N],b[N]; int main(){ int n,m,l,r; cin>>n>>m; for(int i=1;i<=n;i++) cin>>b[i]; for(int i=1;i<=n;i++) a[i]=a[i-1]+b[i]; whil

  • 前缀和与差分模板(互逆运算)2022-01-02 14:06:57

    序列和 #include<iostream> using namespace std; const int N=100010; int a[N],b[N]; int main(){ int n,m,l,r; cin>>n>>m; for(int i=1;i<=n;i++) cin>>b[i]; for(int i=1;i<=n;i++) a[i]=a[i-1]+b[i]; whil

  • 洛谷 P1618 三连击(升级版)2021-12-28 15:05:13

    这就是一篇看完题解之后写后的题解,哈哈哈哈哈哈哈 原题目传送门 题目的大概描 这个题让我们输入三个数a,b,c,使得在三位数中(100-999)存在三个数满足我们输入的比例(例如:1:2:3的三位数有192:384:576等),并把它们全部输出出来。 这道题特别像全排列问题,把三位数从头到位生成一边,看看有没有

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有