scanf

A1079. Total Sales of Supply Chain

走远了吗. 提交于 2020-03-03 09:52:19
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. Starting from one root supplier, everyone on the chain buys products from one's supplier in a price P and sell or distribute them in a price that is r% higher than P. Only the retailers will face the customers. It is assumed that each member in the supply chain has exactly one supplier except the root supplier, and there is no supply cycle. Now given a supply chain, you are supposed to tell the total sales from all the retailers. Input

PAT A1032 Sharing

生来就可爱ヽ(ⅴ<●) 提交于 2020-03-03 08:31:25
题目难度:一颗半星 题目大意:就是两个链表,需要找出最开始的公共节点。 题目坑点:这道题又颠覆了我之前的认知,就是关于cin和scanf的东西,之前我都是用cin超时,然后用scanf不超时,但是这次就不一样了,用scanf反而超时。。。郁闷,希望可以有大佬指点一下,区别在哪儿,为啥我这里用scanf就会超时。 刚开始用了初试里面王道上面的那个解题的方法,但是一个测试点超时,然后换了一个思路,就ac了。 代码如下: #include < iostream > #include < stdlib . h > #include < queue > #include < stack > #include < algorithm > #include < map > #include < set > #include < cstring > using namespace std ; typedef struct { char data ; int next ; } Node ; Node list [ 101000 ] ; int main ( ) { int as , bs , num , loc ; cin >> as >> bs >> num ; for ( int i = 0 ; i < num ; i ++ ) { cin >> loc ; cin >> list [ loc

Educational Codeforces Round 12

[亡魂溺海] 提交于 2020-03-03 05:23:18
665A - Buses Between Cities 20171129 奇奇怪怪的小数学题...推推式子就好了,边界情况比较蛋疼 #include<stdlib.h> #include<stdio.h> #include<math.h> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int a,ta,b,tb,h,m,t; int main() { scanf("%d%d%d%d",&a,&ta,&b,&tb);a*=2,ta*=2,b*=2,tb*=2; scanf("%d:%d",&h,&m),t=60*h+m-300;t*=2; printf("%d\n",min(t+ta-1,2278)/b-(t-tb+1<=-1?-b:t-tb+1)/b); return 0; } View Code 665B - Shopping 20171129 按题意模拟即可 #include<stdlib.h> #include<stdio.h> #include<math.h> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n,m,x,k,a,p[101],ans;

Week 1 训练篇

让人想犯罪 __ 提交于 2020-03-02 21:40:06
Week 1 总结 训练篇 : Round 1: 第一轮的题目都比较简单 1.工作安排 http://47.95.147.191/contest/5/problem/A 描述 Farmer John 有太多的工作要做!为了让农场高效运转,他必须靠他的工作赚钱,每项工作花一个单位时间。 他的工作日从0时刻开始,有 个单位时间。在任一时刻,他都可以选择编号 1 ~ N 的 N 项工作中的任意一项工作来完成。 因为他在每个单位时间里只能做一个工作,而每项工作又有一个截止日期,所以他很难有时间完成所有 N 个工作,虽然还是有可能。 对于第 i 个工作,有一个截止时间 ,如果他可以完成这个工作,那么他可以获利 。 在给定的工作利润和截止时间下,FJ能够获得的利润最大为多少呢? 输入 第1行:一个整数N. 第2~N+1行:第 i +1行有两个用空格分开的整数: 和 . 输出 输出一行,里面有一个整数,表示最大获利值。 这个题目就是建立一个利润的最大生成树,然后从最后一天开始往前操作。因为每一天可以完成DDL是之后的工作而不能DDL是完成之前的。 #include<stdio.h>#include<algorithm>#include<queue>#include<iostream> using namespace std;struct VD{ long long d,p; bool

double型(双精度型)的打印(printf) 和scanf

别来无恙 提交于 2020-03-02 19:16:15
ouble型,printf()用%f输出,而scanf用%lf来接受输入。 格式 printf scanf %c int char * %d, %i int int * %o, %u, %x unsigned int unsigned int * 格式 printf scanf %ld, %li long int long int * %lo, %lu, %lx unsinged long int unsigned long int * %hd, %hi int short int * %ho, %hu, %hx unsigned int unsigned short int * %e, %f, %g double float * %le, %lf, %lg n/a double * %s char * char * %[...] n/a char * %p void void ** %n int * int * %% none none 来源: oschina 链接: https://my.oschina.net/u/240535/blog/2962752

2019春第九周作业

醉酒当歌 提交于 2020-03-02 18:13:52
第八周作业 这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass4-2018/homework/3126 我在这个课程的目标是 使用结构解决问题 这个作业在那个具体方面帮助我实现目标 能用结构解决一些不用结构很难做出来的题 参考文献 C语言程序设计II 一、本周完成的作业 基础作业 函数题 6-1 按等级统计学生成绩 (20 分) 本题要求实现一个根据学生成绩设置其等级,并统计不及格人数的简单函数。 函数接口定义: int set_grade( struct student *p, int n ); 其中p是指向学生信息的结构体数组的指针,该结构体的定义为: struct student{ int num; char name[20]; int score; char grade; }; n是数组元素个数。学号num、姓名name和成绩score均是已经存储好的。set_grade函数需要根据学生的成绩score设置其等级grade。等级设置:85-100为A,70-84为B,60-69为C,0-59为D。同时,set_grade还需要返回不及格的人数。 裁判测试程序样例: #include <stdio.h> #define MAXN 10 struct

ACM模板(持续补完)

半腔热情 提交于 2020-03-02 15:15:36
KMP 1 #include<cstring> 2 #include<algorithm> 3 #include<cstdio> 4 using namespace std; 5 const int maxn=2000; 6 char a[maxn+50],s[maxn+50]; 7 int next[maxn+50][maxn+50]; 8 int len1,len,t; 9 int main() 10 { 11 scanf("%d\n",&t); 12 while(t--) 13 { 14 s[0]='0'; 15 scanf("%s",s+1); 16 len=strlen(s); 17 for(int k=1;k<len;++k) 18 { 19 int j=k-1; 20 next[k][k]=k-1; 21 for(int i=k+1;i<len;++i) 22 { 23 while(j>=k&&s[j+1]!=s[i]) j=next[k][j]; 24 if(s[j+1]==s[i]) ++j; 25 next[k][i]=j; 26 } 27 } 28 long long ans=0; 29 for(int k=1;k<len;++k) 30 { 31 int j=k-1; 32 for(int i=1;i<len;++i) 33 { 34 while(j>=k&

2020牛客寒假算法基础集训营1 题解

浪子不回头ぞ 提交于 2020-03-02 14:39:45
A:honoka和格点三角形 输入描述: 两个正整数和( 2 ≤ n , m ≤ 1 0 9 2\ ≤n,m≤10^9 2 ≤ n , m ≤ 1 0 9 )( 2 ≤ n , m ≤ 1 0 9 2 ≤n,m≤10^9 2 ≤ n , m ≤ 1 0 9 ) 输出描述 : 面积为1的格点三角形的数量,对 1 0 9 + 7 10^9+7 1 0 9 + 7 取模的结果。 示例1 输入 2 3 输出 6 说明 格点如下: * * * * * * 不妨设左下角坐标为 ( 1 , 1 ) ,右上角坐标为到 ( 3 , 2 ) 。 那么三点坐标可选: ( 1 , 1 )( 1 , 2 )( 3 , 1 ) ( 1 , 1 )( 1 , 2 )( 3 , 2 ) ( 1 , 1 )( 2 , 2 )( 3 , 1 ) ( 1 , 1 )( 3 , 1 )( 3 , 2 ) ( 1 , 2 )( 2 , 1 )( 3 , 2 ) ( 1 , 2 )( 3 , 1 )( 3 , 2 ) 所以共有 6 个。 示例2 输入 100 100 输出 7683984 就是一个分类讨论,据说有公式,不是特别清楚,注意多加()%mod ,玄学mod 代码 # include <iostream> # include <cstdio> # include <cstring> using namespace

Educational Codeforces Round 11

ⅰ亾dé卋堺 提交于 2020-03-02 04:34:38
这个东西已经咕咕咕了快一年的时间,想想昨天校内训练差点被学弟们爆锤,真是怠惰啊..._(:з」∠)_ 从开始刷教育轮的蓝名水平,到“ Educational Round补完计划 ”开启时的紫名中游水平,再到现在个人水平也游到了黄名中下游,应该是不需要用狂刷div2的水题来提升自我了,不过既然当初挖了这个坑,还是要补一下的...一年多时间教育轮的轮数也从当时的50到了现在的80+,感觉很难在退役前补完了_(:з」∠)_先试试能不能把50轮之前的都搞定吧... 660A - Co-prime Array 20171129 看了一眼我当年写的代码...这什么憨批玩意嘛_(:з」∠)_ #include<stdlib.h> #include<stdio.h> #include<math.h> #define N 1001 #include<vector> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n,k,a[N],p[20]; vector<int>ans; int gcd(int x,int y){return y?gcd(y,x%y):x;} int find(int x,int y) { for(int i=1;i<20;i++) if(gcd(x,p[i])=

关于C/C++中的输入的选择

爱⌒轻易说出口 提交于 2020-03-01 21:25:21
1、SCANF(相对PRINTF): scanf() 函数用于从标准输入(键盘)读取并格式化;通常情况下我们须知变量的类型 2、GETCHAR(相对PUTCHAR): getchar()从键盘中获取单一的字符(包括空格) 3、GETS(相对PUTS): 这个函数很简单,只有一个参数。参数类型为 char* 型,即 str 可以是一个字符指针变量名,也可以是一个字符数组名。 gets() 函数的功能是从输入缓冲区中读取一个字符串存储到字符指针变量 str 所指向的内存空间; gets() 函数不仅比 scanf 简洁,而且, 就算输入的字符串中有空格也可以直接输入, 不用像 scanf 那样要定义多个字符数组。 此外,关于使用 gets() 函数需要注意:使用 gets() 时,系统会将最后“敲”的换行符从缓冲区中取出来,然后丢弃,所以缓冲区中不会遗留换行符。这就意味着,如果前面使用过 gets(),而后面又要从键盘给字符变量赋值的话就不需要吸收回车清空缓冲区了,因为缓冲区的回车已经被 gets() 取出来扔掉了。例如: # include <stdio.h> int main(void) { char str[30]; char ch; printf("请输入字符串:"); gets(str); printf("%s\n", str); scanf("%c", &ch);