入门水题集锦
首先声明,这个水题是相对我而言,很多题新手一眼看不出来解法是蛮正常的,我新手的时候未必比你们好,毕竟还是刷了一段时间的题了,现在能说这些是水题也是我努力的结果呀~
不过我现在写的难题在学长、真·dalao、巨灵神看起来不也是很水的嘛~
A
A+B不提
#include <stdio.h>
int main(void)
{
double a,b;
while(scanf("%lf %lf",&a,&b)!=EOF){
printf("%.4f\n",a+b);
}
return 0;
}
B
同A
#include <stdio.h>
int main(void)
{
long long a,b;
scanf("%lld %lld",&a,&b);
while(a||b){
printf("%lld\n",a+b);
scanf("%lld %lld",&a,&b);
}
return 0;
}
C
一个字符串变成PERPERPER要多少次,直接顺着遍历一遍就好了
#include <bits/stdc++.h>
#define N 10100
#define INF 0x3f3f3f3f
#define LL long long
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
int main()
{
ios::sync_with_stdio(false);
string temp;
const string need="PER";
cin>>temp;
int cnt=0,i;
for(i=0;i<temp.size();++i){
if(temp[i]!=need[i%3]){
++cnt;
}
}
cout<<cnt<<endl;
return 0;
}
D
不提
#include <stdio.h>
int main()
{
int t,n,i,j,x1,x2,x3,d,f,sc;
char s[2];
scanf("%d",&t);
for(i=0;i<t;++i){
scanf("%s",s);
if(s[0]=='m'){
sc=90;
}else{
sc=60;
}
scanf("%d %d %d %d %d",&x1,&x2,&x3,&d,&f);
sc=sc-1*x1-2*x2-5*x3-d-f;
if(sc<=0){
printf("Welcome\n");
}else{
printf("%d\n",sc);
}
}
return 0;
}
I
cmath会用了吧
#include <bits/stdc++.h>
#define N 10100
#define INF 0x3f3f3f3f
#define LL long long
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
int main()
{
ios::sync_with_stdio(false);
double f;
int n;
cin>>n;
while(n--){
cin>>f;
cout<<round(12*log(f/440)/log(2)+69)<<endl;
}
return 0;
}
K
BFS模板题
#include <bits/stdc++.h>
#define N 10100
#define INF 0x3f3f3f3f
#define LL long long
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
int mp[101][101];
const int op[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct p{
int x,y,cnt;
bool operator<(const p &a) const {
return cnt>a.cnt;
}
};
int main()
{
ios::sync_with_stdio(false);
int t,n,m;
char temp;
cin>>t;
priority_queue<p> que;
while(t--){
while(!que.empty()){
que.pop();
}
cin>>n>>m;
for(int i=0;i<n;++i){
for(int j=0;j<m;++j){
cin>>temp;
if(temp=='#'){
mp[i][j]=0;
}else if(temp=='@'){
mp[i][j]=0;
que.push((p){i,j,0});
}else if(temp=='.'){
mp[i][j]=1;
}else if(temp=='*'){
mp[i][j]=2;
}
}
}
int ans=-1;
while(!que.empty()){
int tempx=que.top().x,tempy=que.top().y,tempcnt=que.top().cnt;
que.pop();
if(tempx==0||tempy==0||tempx==n-1||tempy==m-1){
ans=tempcnt;
break;
}
for(int i=0;i<4;++i){
if(mp[tempx+op[i][0]][tempy+op[i][1]]){
que.push((p){tempx+op[i][0],tempy+op[i][1],tempcnt+mp[tempx+op[i][0]][tempy+op[i][1]]-1});
mp[tempx+op[i][0]][tempy+op[i][1]]=0;
}
}
}
cout<<ans<<endl;
}
return 0;
}
O
给你N艘船和距离D,每艘船的每光年耗油量、行驶速度、油箱容量,问你多少艘船能到目标位置
#include <bits/stdc++.h>
#define N 10100
#define INF 0x3f3f3f3f
#define LL long long
#define eps 1e-4
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int t,n,s,cnt,v,c,f;
cin>>t;
while(t--){
cnt=0;
cin>>n>>s;
for(int i=0;i<n;++i){
cin>>v>>f>>c;
if(f+eps>1.0*s/v*c){
++cnt;
}
}
cout<<cnt<<endl;
}
return 0;
}
R
读懂题目就好了,但是这个题目解释起来好麻烦啊不想说了
#include <bits/stdc++.h>
#define N 10100
#define INF 0x3f3f3f3f
#define LL long long
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
int num[31];
int main()
{
ios::sync_with_stdio(false);
int n,t,mi,ma,temp;
cin>>t;
while(t--){
mi=101,ma=0;
cin>>n;
while(n--){
cin>>temp;
if(temp<mi){
mi=temp;
}
if(temp>ma){
ma=temp;
}
}
cout<<2*(ma-mi)<<endl;
}
return 0;
}
S
每买三个物品会免一个物品的单,不过是三个物品中最便宜的。就每次都选最贵的三个,这样也就每次都让你能免单的最贵的免单了
#include <bits/stdc++.h>
#define N 10100
#define INF 0x3f3f3f3f
#define LL long long
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
inline bool cmp(int a,int b){
return a>b;
}
int num[2*N];
int main()
{
ios::sync_with_stdio(false);
int t,n;
cin>>t;
while(t--){
cin>>n;
for(int i=0;i<n;++i){
cin>>num[i];
}
sort(num,num+n,cmp);
int sum=0;
for(int i=2;i<n;i+=3){
sum+=num[i];
}
cout<<sum<<endl;
}
return 0;
}
V
题意明确,不提
#include <stdio.h>
int main()
{
int T,N,i,j,jd,st,b,pos1,pos2,pos3,x;
scanf("%d",&T);
for(i=0;i<T;i++){
scanf("%d",&N);
st=b=jd=0;
for(j=0;j<N;j++){
scanf("%d",&x);
switch(x){
case 0 :if(!st++){
pos1=j+1;
}break;
case 2 :if(!jd++){
pos2=j+1;
}break;
case 5 :if(!b++){
pos3=j+1;
}break;
}
}
if(b&&st==N-1){
printf("%d\n",pos3);
}else if(jd&&b==N-1){
printf("%d\n",pos2);
}else if(st&&jd==N-1){
printf("%d\n",pos1);
}else{
printf("No winner\n");
}
}
return 0;
}
W
如果现在的这一项比后面的大,后面的就合并直到后面一项比前面的大,然后更新和
#include <bits/stdc++.h>
#define N 10100
#define INF 0x3f3f3f3f
#define LL long long
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
int main()
{
ios::sync_with_stdio(false);
LL now_sum,last_sum;
int n,t,temp,cnt;
cin>>t;
while(t--){
cin>>n;
last_sum=cnt=0;
now_sum=0;
for(int i=0;i<n;++i){
cin>>temp;
now_sum+=temp;
if(now_sum>last_sum){
last_sum+=now_sum;
now_sum=0;
++cnt;
}
}
cout<<cnt<<endl;
}
return 0;
}
Z
排序然后输出中位数就好
#include <bits/stdc++.h>
#define N 10100
#define INF 0x3f3f3f3f
#define LL long long
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
int num[20*N];
int main()
{
ios::sync_with_stdio(false);
int n,i;
while(cin>>n){
for(i=0;i<n;++i){
cin>>num[i];
}for(;i<2*n;++i){
cin>>num[i];
}
sort(num,num+2*n);
cout<<num[n-1]<<endl;
}
return 0;
}