随笔分类 - 推理技巧题
摘要:View Code 1 /* 2 题意:在一个滑雪道上没个单位长度可以减速 1 ,也可 3 增速 1 ,也可保持不变,滑雪道中有一些corner,在此处要限制速度, 4 问在整个滑雪过程中可以获得最大速度。 5 思路: 1.先求出每点可以允许的最大速度 6 2.然后从起点起计算每点能达到的速度 7 3.求最大速度 8 */ 9 #include<iostream>10 #include<cstdio>11 #include<algorithm>12 #include<cstdlib>13 using namespace std;14 15 con
        阅读全文
                
摘要:View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<stack> 6 using namespace std; 7 8 char ch[1000]; 9 stack <int> q;10 11 void slovenum()12 {13 int i,len;14 while(!q.empty())q.pop();15 int x=0;16 len=strlen(ch);17 
        阅读全文
                
摘要:View Code 1 /* 2 题非常简单,但是英文 看了好久才理解意思 3 题意: 4 多人进行投标 每个人可以对同一物品可以投多次标但 价格必须 5 不一样。 6 1.若有一个投标价值出现一次则这个投标人胜出 7 2.若 没有唯一的投标价则 那个投标价投的次数最少,这个价格就是 8 胜出的价格,若有多个价格 有最少的投标次数 9 则去价格最低者,那个人第一次投这个价,谁胜出 10 思路:11 开辟一个数组 num[],记录各个价格投标的次数12 然后从 1 开始搜到上限找出投标次数最少的和最先13 投标者14 需要用一个Struct数组存放{投标人,价格} 15 */16 #incl..
        阅读全文
                
摘要:View Code 1 /* 2 开始把这个题想复杂了, 3 其实很简单: 4 思路: 5 找出所有度数为 1 的节点数,消除这些度数为1的节点至少需要多少遍 6 原理: 7 度数为 1 的节点只要把与之相连的那个节点去掉就成孤立的了 8 因此我们再加一条边即使原来的那个邻接点坏了 还有一个边与之相连 9 */10 11 #include<iostream>12 #include<cstdio>13 #include<cstring> 14 using namespace std; 15 16 short int a[10001];17 18 int mai
        阅读全文
                
摘要:View Code 1 #include<stdio.h> 2 3 int a[1000001]; 4 5 int main() 6 { 7 int i; 8 int n,c,q,x,y,z,t; 9 scanf("%d%d%d",&n,&c,&q);10 while(c--)11 {12 scanf("%d%d%d",&x,&y,&z);13 a[x]+=z;14 a[y+1]-=z;15 }16 17 for(i=1;i<=n;++i)//求出各个人的功劳 18 {19 ...
        阅读全文
                
摘要:View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int T[1001]; 5 int K[1001]; 6 7 int cmp(const void *x,const void *y) 8 { 9 int *m = (int *)x;10 int *n = (int *)y;11 return *m-*n;12 }13 14 int main()15 {16 int i,t;17 while(scanf("%d",&t) != EOF)18 {19 for(i=0;i<t;+
        阅读全文
                
摘要:View Code 1 /* 2 推出:f[n]=2*f[n-1]+1; 3 f[1]=1; 4 可得:f[n]=2^n-1; 5 */ 6 #include<iostream> 7 #include<cstdio> 8 using namespace std; 9 10 const int x=1000000;11 void gao(int n)12 {13 long long s=1,t=2;//注意范围 14 for(;n;n>>=1,t=(t%x)*(t%x),t%=x)15 if(n&1)16 {17 s%=x;18 ...
        阅读全文
                
摘要:View Code 1 /* 2 高次方求模: 3 比如a 的 b次方 对c 求模: 4 比如:2^10次方,对3求模 5 10的二进制是1010相当于2^10=2^8*2^2 6 我们看对应的二进制位是否为1,若为1则乘上2^i次方 7 若为0则不乘(注意一个规律:第i位2^i=(2^i-1)*(2^i-1)) 8 */ 9 #include<iostream>10 #include<cstdio>11 using namespace std;12 13 long long a,b,c;14 void han()15 {16 long long t,s;17 for(
        阅读全文
                
摘要:View Code 1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 5 int a[3400000]={0}; 6 int main() 7 { 8 int m,n,i,t; 9 scanf("%d%d",&m,&n);10 for(i=0;i<m;++i)11 {12 scanf("%d",&t);13 a[t/32] |=(1<<(t%32));//一个int 表示32位 14 } //商相同,余数不同,
        阅读全文
                
摘要:View Code 1 /* 2 思路(借鉴): 3 n!阶乘能分解出几个5,就有几个0 4 因为5与偶数相乘的一个零,偶数是充足的 5 6 */ 7 #include<iostream> 8 using namespace std; 9 int a[10000001];10 int main()11 {12 int i,n,m;13 for(i=1;i<10000001;++i)14 {15 if(i<5){a[i]=0;continue;}16 int k=i/5;// i先分解出一个5,他的商还能分解几个 17 a[i]=k...
        阅读全文
                
摘要:View Code 1 /* 2 观察题目可以发现: 3 划分一个整数 如:n 4 分别是以 n开头,以n-1开头...,以1开头等 5 相当于最大的是开头的那个 其余的数不能超过这个数 6 7 */ 8 9 #include<iostream>10 using namespace std;11 int query(int n,int x)12 {13 if(x<1||n<1)return 0;14 if(x==1||n==1)return 1;15 if(n<x)return query(n,n);//对于n<x说明整数是n 最大也是以n开头 16 if(
        阅读全文
                
摘要:View Code 1 2 /* 3 思路: 4 比如:n=100,m=5 5 100是有20个5组成的 6 因此100减去一个5是95 ,减去两个是90 7 ...减去19个是0. 8 则是5 倍数的数有二十个(不是m的倍数的不能分解出m) 9 ,从这二十个10 数中各分解出一个5则有20个511 这二十个数变为12 20,19,18,...,1即 20的阶乘13 相当于转移到求20的阶乘能分解多少个m了14 依次类推! 15 */16 #include<iostream>17 using namespace std;18 int main()19 {20 int t,n,m;2
        阅读全文
                
摘要:View Code 1 /* 2 题意: 3 共有N个,一次最多取M 个 4 思路: 5 这是一道技巧性的题,考察从题中找规律! 6 假设有a ,b两个人 a 先取 看是否能赢: 7 若a能赢则最后一次是a取,且一定是取了M个 8 而倒数第二次是b取,且一定是取1个, 9 因此倒着看就是一个状态转移了总数为N个,总数为N-(M+1),N-2*(M+1).....10 情况下a先取,能赢得问题了 11 */12 #include<iostream>13 using namespace std;14 int n,m;15 int main()16 {17 int t;18 cin>
        阅读全文
                
                    
                
浙公网安备 33010602011771号