c/c++竞赛
轻抿一笑
这个作者很懒,什么都没留下…
展开
-
acwing132.小组队列
代码如下#include<bits/stdc++.h>using namespace std;const int N=100010;map<int,int> m1;int main(){ int times=1; int qnum; while(cin>>qnum,qnum!=0) { cout<<"Scenario #"<<times<<endl; times++; queue <int&g原创 2021-11-14 12:17:21 · 834 阅读 · 0 评论 -
统计方形题解
答案如下:#include<bits/stdc++.h>using namespace std;int main(){ long long n,m; cin>>n>>m; long long an1=0,an2=0,sum; sum=(n*(n+1)/2)*(m*(m+1)/2); long long x=n,y=m; for(int i=1;i<=min(m,n);i++) { an1+=x*y; x--; y--; } an原创 2021-07-24 16:31:04 · 122 阅读 · 0 评论 -
Matrix Chain Multiplication UVA - 442
Suppose you have to evaluate an expression like ABCDE where A,B,C,D and E are matrices.Since matrix multiplication is associative, the order in which multiplications are performed is arbitrary.However, the number of elementary multiplications needed stro原创 2021-06-03 10:17:55 · 85 阅读 · 0 评论 -
Rails UVA - 514
答案如下:#include<bits/stdc++.h>using namespace std;typedef set<int> Set;map<Set,int> IDcache;vector<Set> Setcache;int ID(Set x){ if(IDcache.count(x)) return IDcache[x]; Setcache.push_back(x); return IDcache[x]=Setcache.size原创 2021-05-22 11:44:11 · 68 阅读 · 0 评论 -
Team Queue UVA - 540
答案如下:#include<bits/stdc++.h>using namespace std;const int maxt=1010;int main(){ int kase=0,tn=0; while(scanf("%d",&tn)==1&&tn) { cout<<"Scenario #"<<++kase<<endl; map<int,int>fteam; for(int i=0;i&l原创 2021-05-15 10:49:40 · 84 阅读 · 0 评论 -
Ananagrams UVA - 156
答案如下:#include<bits/stdc++.h>using namespace std;map<string,int>cnt;vector<string>words;string repr(const string &s){ string ans=s; for(int i=0;i<ans.length();i++) ans[i]=tolower(ans[i]); sort(ans.begin(),ans.end());原创 2021-05-13 10:57:22 · 82 阅读 · 0 评论 -
The Blocks Problem UVA - 101
答案如下:#include<bits/stdc++.h>using namespace std;int n;vector<int>pile[30];void find_block(int a,int& p,int& h){ for(p=0;p<n;p++) for(h=0;h<pile[p].size();h++) if(pile[p][h]==a) return;}void clear_above(int p,int原创 2021-05-08 11:25:26 · 76 阅读 · 0 评论 -
Flip Flow
答案如下:#include<bits/stdc++.h>using namespace std;int main(){ int now,twice,up=0,down=0; int change[1005]={0}; scanf("%d%d%d",&now,&down,&twice); for(int i=0;i<twice;i++) scanf("%d",&change[i]); int next=0; for(int t=0原创 2021-05-03 11:55:09 · 144 阅读 · 0 评论 -
Adolescent Architecture
答案如下:#include<bits/stdc++.h>using namespace std;bool cmp(int a,int b){ return a>b;}int main(){ char look1[]="cube"; char look2[]="cylinder"; int n,ok=1; cin>>n; int cube1[105]={0},cylinder1[105]={0}; int numcu=0,numcy=0; fo原创 2021-05-03 11:54:20 · 128 阅读 · 0 评论 -
The Dole Queue UVA - 133
代码如下:#include<bits/stdc++.h>using namespace std;#define maxn 25int n,k,m,a[maxn];int go(int p,int d,int t){ while(t--) do { p=(p+d+n-1)%n+1; } while(a[p]==0); return p;}int main(){ while(scanf("%d%d%d",&n,&k,&m)==3&&原创 2021-05-03 11:53:42 · 58 阅读 · 0 评论 -
Hangman Judge UVA - 489
答案如下:#include<bits/stdc++.h>using namespace std;#define maxn 100char s1[maxn],s2[maxn];int leftword=0,win=0,lose=0,chance=0;void guess(char ch){ int bad=1; for(int i=0;i<strlen(s1);i++) if(ch==s1[i]) { bad=0; s1[i]=' '; leftw原创 2021-05-02 10:19:49 · 51 阅读 · 0 评论 -
Ancient Cipher UVA - 1339
答案如下:#include<bits/stdc++.h>using namespace std;int main(){ char a[100],b[100]; while(scanf("%s%s",a,b)==2) { int cnt1[26]={0}; int cnt2[26]={0}; for(int i=0;i<strlen(a);i++) cnt1[a[i]-'A']++; for(int i=0;i<strlen(b);i++)原创 2021-05-01 11:40:38 · 81 阅读 · 0 评论 -
买花
链接:https://ac.nowcoder.com/acm/contest/11746/I来源:牛客网题目描述情人节马上要到了,阳阳想送出n朵花给喜欢的妹妹,他打算提前开始买。但是,因为他有强迫症,所有的花要分k天买(k>1,即不能一天全买完),第一天他可以买任意朵花,之后每一天买花的数量为前一天的两倍,(如若第一天买4朵,第二天就要买8朵,以此类推)。现在离情人节还有15天(k≤15),请你告诉阳阳,他能不能刚好买到n朵花。输入描述:多组输入。第一行一个正整数T(1<=T<原创 2021-01-31 17:50:30 · 265 阅读 · 0 评论 -
Babelfish
You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.InputInput consists of up to 100,000 dictionary entries, followed by原创 2021-01-25 22:40:51 · 128 阅读 · 0 评论 -
Broken Keyboard(deque解法)
You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problemwith the keyboard is that sometimes the “home” key or the “end” key gets automatically pressed(internally).You’re not aware of this issue, since you’re focu原创 2021-01-25 22:39:57 · 200 阅读 · 0 评论 -
Train Swapping
At an old railway station, you may still encounter one of the last remaining “train swappers”. A trainswapper is an employee of the railroad, whose sole job it is to rearrange the carriages of trains.Once the carriages are arranged in the optimal order,原创 2021-01-24 17:07:49 · 283 阅读 · 1 评论 -
Who‘s in the Middle
FJ is surveying his herd to find the most average cow. He wants to know how much milk this ‘median’ cow gives: half of the cows give as much or more than the median; half give as much or less.Given an odd number of cows N (1 <= N < 10,000) and their原创 2021-01-24 16:20:30 · 128 阅读 · 0 评论 -
买房子
描述某程序员开始工作,年薪N万,他希望在中关村公馆买一套60平米的房子,现在价格是200万,假设房子价格以每年百分之K增长,并且该程序员未来年薪不变,且不吃不喝,不用交税,每年所得N万全都积攒起来,问第几年能够买下这套房子?(第一年年薪N万,房价200万)输入一行,包含两个正整数N(10 <= N <= 50), K(1 <= K <= 20),中间用单个空格隔开。输出如果在第20年或者之前就能买下这套房子,则输出一个整数M,表示最早需要在第M年能买下,否则输出Imposs原创 2021-01-23 16:31:47 · 128 阅读 · 0 评论 -
Election Time
答案如下#include<iostream>#include<algorithm>using namespace std;const int maxn=50010;struct node{ int a; int b; int num;}cow[maxn];int cmpa(node p,node q){ if(p.a==q.a) return p.b>q.b; return p.a>q.a;}int cmpb(node p,node q)原创 2021-01-23 00:25:54 · 74 阅读 · 0 评论 -
Bode Plot
答案如下#include<cstdio>#include<cmath>int main(){ int i,n; double vr,vs,r,c,w; scanf("%lf%lf%lf%d",&vs,&r,&c,&n); for(int i=0;i<n;i++) { scanf("%lf",&w); vr=c*r*w*vs/sqrt(1+c*c*r*r*w*w); printf("%.3lf\n",vr);原创 2021-01-22 00:29:30 · 348 阅读 · 1 评论 -
Necklace
答案如下#include<cstdio>int main(){ double Vt,V0; while(~scanf("%lf%lf",&Vt,&V0)&&Vt+V0) { if(Vt<=V0) printf("0\n"); else if(Vt<=2*V0) printf("1\n"); else { if(0.5*Vt/V0-(int)(0.5*Vt/V0)==0.5) printf("0\n");原创 2021-01-22 00:09:44 · 132 阅读 · 0 评论 -
Specialized Four-Digit Numbers
Specialized Four-Digit Numbers代码如下#include<cstdio>int want(int goal,int n){ int final=0; for(;goal;goal/=n) { final+=goal%n; } return final;}int main(){ for(int i=2992;i<10000;i++) { int a=want(i,10); if(a==want(i,12)&&原创 2021-01-18 17:23:42 · 65 阅读 · 0 评论 -
纪念品分组
链接:https://ac.nowcoder.com/acm/problem/16640来源:牛客网题目描述元旦快到了,校学生会让乐乐负责新年晚会的纪念品发放工作。为使得参加晚会的同学所获得 的纪念品价值相对均衡,他要把购来的纪念品根据价格进行分组,但每组最多只能包括两件纪念品, 并且每组纪念品的价格之和不能超过一个给定的整数。为了保证在尽量短的时间内发完所有纪念品,乐乐希望分组的数目最少。你的任务是写一个程序,找出所有分组方案中分组数最少的一种,输出最少的分组数目。输入描述:第 1 行包括一个原创 2021-04-03 15:03:30 · 101 阅读 · 0 评论 -
统计数字
链接:https://ac.nowcoder.com/acm/problem/16643来源:牛客网题目描述某次科研调查时得到了n个自然数,每个数均不超过1500000000(1.5109)。已知不相同的数不超过10000个,现在需要统计这些自然数各自出现的次数,并按照自然数从小到大的顺序输出统计结果。输入描述:第1行是整数n,表示自然数的个数。第2~n+1行每行一个自然数。输出描述:输出m行(m为n个自然数中不相同数的个数),按照自然数从小到大的顺序输出。每行输出两个整数,分别是自然数和该原创 2021-04-01 21:07:37 · 247 阅读 · 0 评论 -
图书管理员
1.链接:https://ac.nowcoder.com/acm/problem/16422来源:牛客网题目描述图书馆中每本书都有一个图书编码,可以用于快速检索图书,这个图书编码是一个正整数。每位借书的读者手中有一个需求码,这个需求码也是一个正整数。如果一本书的图书编码恰好以读者的需求码结尾,那么这本书就是这位读者所需要的。小 D 刚刚当上图书馆的管理员,她知道图书馆里所有书的图书编码,她请你帮她写一个程序,对于每一位读者,求出他所需要的书中图书编码最小的那本书,如果没有他需要的书,请输出-1。原创 2021-03-30 22:01:48 · 214 阅读 · 0 评论 -
数位五五
链接:https://ac.nowcoder.com/acm/problem/22168来源:牛客网题目描述求出a到b之间有多少个数数位之和为5的倍数输入描述:输入一行包含两个整数x,y (0 \le x, y \le 10000000≤x,y≤1000000)输出描述:输出一个整数示例1输入复制10 20输出复制2说明14和19的数位和为5和10,符合条件答案如下:#include<bits/stdc++.h>using namespace std;in原创 2021-03-30 21:04:03 · 414 阅读 · 0 评论 -
更相减损术
链接:https://ac.nowcoder.com/acm/problem/22164来源:牛客网题目描述利用更相减损术求两个整数的最大公约数,即每次将较大的数变成大数减去小数的值输入描述:输入两个正整数,范围在1000000以内输出描述:输出一个整数示例1输入复制4 6输出复制2答案如下:#include<bits/stdc++.h>using namespace std;int main(){ int a,b; cin>>a原创 2021-03-30 20:57:27 · 1057 阅读 · 0 评论 -
牛牛学数列3
链接:https://ac.nowcoder.com/acm/problem/22158来源:牛客网题目描述牛牛准备继续进阶,计算更难的数列输入一个整数n,计算 1+1/(1-3)+1/(1-3+5)+…+1/(1-3+5-…+2n-1)的值输入描述:输入一个整数输出描述:输出一个浮点数,保留3位小数示例1输入复制1输出复制1.000答案如下:#include<bits/stdc++.h>using namespace std;int main(){原创 2021-03-30 20:52:06 · 633 阅读 · 0 评论 -
1005好玩的数列
链接:https://ac.nowcoder.com/acm/problem/21169来源:牛客网题目描述斐波纳契数列是这样的数列:f1 = 1f2 = 1f3 = 2f4 = 3…fn = f(n-1) + f(n-2)输入一个整数n求fn输入描述:一个整数n, n<= 45输出描述:一个整数fn示例1输入复制3输出复制2示例2输入复制9输出复制34备注:n<=45,请注意时间限制。答案如下:#include<bits/原创 2021-03-28 23:59:50 · 142 阅读 · 0 评论 -
Happy New Year!
链接:https://ac.nowcoder.com/acm/contest/9983/D来源:牛客网题目描述还有一个周就要过年啦!这一天牛牛盯着新的台历出神,他突然想知道对于第\mathit nn年来说,大于\mathit nn且与\mathit nn的数位和相同的最小年份是多少。一个数字的数位和等于他各数位上的数字之和,例如\text 20212021的数位和等于\text 2+0+2+1=52+0+2+1=5。输入描述:一个正整数\mathit nn。2021\leq n \leq 20原创 2021-02-08 17:09:05 · 197 阅读 · 0 评论 -
限制不互素对的排列
链接:https://ac.nowcoder.com/acm/contest/9981/I来源:牛客网题目描述输入一个数 ,请构造一个长度为 的排列,使得其中正好有 对相邻的数gcd(最大公约数)大于 。排列是指 到 一共 个数,每个数都出现过且仅出现过 次。例如, 是一个排列,而 、 则不是排列输入描述:两个整数 和 ,用空格隔开。输出描述:如果不存在可行的构造方案,输出-1。否则输出一行 个数,用空格隔开。如果有多组可行的构造方案,输出任意一组即可。示例1输原创 2021-02-04 11:04:24 · 122 阅读 · 0 评论 -
上进的凡凡
链接:https://ac.nowcoder.com/acm/contest/11746/C来源:牛客网题目描述凡凡是一个上进的人,他的人生没有下坡路,他也讨厌带有”下坡路“的东西。所以,对于凡凡来说,只有非降序的数组才是nice的(如:1,2,2,3,4,5,5);若数组元素个数为1,也满足非降序,也是nice的。现在有一个长度为n的数组,凡凡想知道它的子数组中有多少个数组是nice的。你能帮帮他吗?对于子数组的定义,如果可以通过从开头和从结束分别删除若干个(可以为零或全部,前后删除个数不必原创 2021-02-01 13:04:27 · 185 阅读 · 0 评论 -
数羊
链接:https://ac.nowcoder.com/acm/contest/11746/H来源:牛客网题目描述憨憨小杨晚上睡不着觉,就开始数羊,她觉得一只一只数太慢了,突发奇想出了一种新的数羊方式,羊羊数量A(n,m)由两个整形变量n和m决定,计算方式如下:现在给出n和m的值,请你帮小杨数数一共有多少只羊。输入描述:多组输入。第一行包含一个整数T(1≤T≤1000),表示有T组测试数据。每组测试数据包含一行,包含两个整数n(1≤n≤10^9)和m(0≤m≤2).输出描述:对每一组输入,原创 2021-02-01 12:16:38 · 320 阅读 · 0 评论 -
Seek the Joker I
链接:https://ac.nowcoder.com/acm/contest/11746/D来源:牛客网题目描述长达数日的春日祭终于告一段落,作为巫女的朝野芳乃在打扫完神社本决定好好享受一下久违的宁静。然而守护了神刀数百年的丛雨难耐寂寞,希望芳乃能陪她一起玩扑克消解愁闷。芳乃并不擅长市井的游戏,所以总是输多赢少。而昨日被芳乃的神乐舞深深吸引,以致一早就前来建实神社希望能再睹芳华的你碰巧听见了此事。尽管不知道为什么美丽的巫女要自言自语地为玩扑克而苦恼,但你毅然决然地毛遂自荐,希望能为芳乃一解眉间愁。原创 2021-02-01 10:18:15 · 133 阅读 · 0 评论 -
Digit Counting UVA - 1225
答案如下:#include<bits/stdc++.h>using namespace std;int main(){ int n; cin>>n; while(n--) { int want[10]={0}; int x; cin>>x; for(int i=x;i>=1;i--) { int temp1=i; while(temp1) { int temp=temp1%10; want[tem原创 2021-04-25 18:38:44 · 77 阅读 · 0 评论 -
Molar mass UVA - 1586
答案如下#include<bits/stdc++.h>using namespace std;const double c=12.01,h=1.008,o=16.00,n=14.01;int main(){ int x; cin>>x; for(int i=0;i<x;i++) { char s[100]; cin>>s; double an=0; for(int i=0;i<strlen(s);i++) {原创 2021-04-25 17:55:25 · 56 阅读 · 0 评论 -
Score UVA - 1585
答案如下:#include<bits/stdc++.h>using namespace std;int main(){ int n; cin>>n; while(n--) { char s[100]; cin>>s; int temp=0,an=0; for(int i=0;i<strlen(s);i++) { if(s[i]=='X') { temp=0; continue; } if(s[i]=='O'原创 2021-04-25 16:30:13 · 80 阅读 · 0 评论 -
Where is the Marble? UVA10474
答案如下:#include<bits/stdc++.h>using namespace std;#define maxn 10010int main(){int n1,n2,kase=0;while(scanf("%d%d",&n1,&n2)==2&&n1){int stone[maxn],want[maxn];for(int i=0;i<n1;i++)cin>>stone[i];for(int i=0;i<n2;i原创 2021-04-23 16:47:04 · 69 阅读 · 0 评论 -
UVa1584 环状序列(Circular Sequence)
答案如下#include<bits/stdc++.h>using namespace std;#define maxn 105int wantless(const char*s,int p,int q){ int n=strlen(s); for(int i=0;i<n;i++) { if(s[(i+p)%n]!=s[(i+q)%n]) return s[(p+i)%n]<s[(q+i)%n]; } return 0;}int main(){ i原创 2021-04-22 17:11:31 · 91 阅读 · 0 评论 -
UVa1583 生成元
给出两种方法吧第一种:#include<bits/stdc++.h>using namespace std;void want(int n){ int flag=1; for(int m=1;m<n;m++) { int x=m,y=m; while(x>0) { y+=x%10; x/=10; } if(y==n) { cout<<m<<endl; flag=0; break; }原创 2021-04-22 17:09:07 · 78 阅读 · 0 评论