首页 技术 正文
技术 2022年11月17日
0 收藏 658 点赞 4,033 浏览 2544 个字

A

解法:dfs搜索,注意一个剪枝,否则会超时(听说原本是个dp)?

#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
//#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int n,m,k,MIN;
int v,u,w;
int i,j;
int map[1100][1100];
void dfs(int s,int num,int sum)
{
if(s==n)
{
MIN=min(sum,MIN);
return ;
}
if(num==k)
return ;
for(int i=1;i<=n;i++)
{
if(map[s][i]!=-1&&sum+map[s][i]<=MIN)
dfs(i,num+1,sum+map[s][i]);
}
}
int main()
{
while(~scanf("%d%d%d",&n,&m,&k))
{
if(n+m+k==0) break;
memset(map,-1,sizeof(map));
for(i=0;i<m;i++)
{
cin>>u>>v>>w;
map[u][v]=map[v][u]=w;
}
MIN=inf;
dfs(1,0,0);
if(MIN==inf)
{
puts("CONTINUE LOL!");
}
else
{
printf("%d\n",MIN);
}
}
return 0;
}

B

解法:模拟,移动数组

#include <stdio.h>
int main()
{
int n,q;
int a[100];
while(~scanf("%d%d",&n,&q)&&(n+q))
{
int xi;
int c=1;
for(int i=1;i<=n;i++)
{
a[i-1]=c;
c++;
}
while(q--)
{
scanf("%d",&xi);
int b=a[xi-1];
for(int i=xi-1;i>=0;i--)
{
a[i]=a[i-1];
}
a[0]=b;
}
for(int i=0;i<n;i++)
{
printf("%d ",a[i]);
}
printf("\n");
}
return 0;
}

C

解法:字符串匹配

#include<stdio.h>
#include<string.h>
int main()
{
char a[100000];
char b[100000];
int n;
while(scanf("%d",&n)!=EOF)
{
while(n--)
{
scanf("%s%s",a,b);
if(strstr(b,a)!=NULL)
printf("YES\n");
else
printf("NO\n");
}
}
}

D

解法:链接:http://blog.csdn.net/ramay7/article/details/50328357

#include <stdio.h>
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
long long u, d, ans, cases = 0,t;
while (~scanf("%lld%lld", &u, &d))
{
if(u==0&&d==0) break;
ans = 0;
while (d)
{
ans += u / d;
t = u%d;
u = d;
d = t;
}
printf("%lld\n", ans);
}
return 0;
}

E

解法:链接http://acm.hdu.edu.cn/showproblem.php?pid=1205

#include <stdio.h>
int a[1000100];
int main()
{
int i,n,t,max;
int sum;
scanf("%d",&t);
while(t--)
{
sum=0;
scanf("%d",&n);
max=-1;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
if(a[i]>max) max=a[i];
}
// printf("%d %d\n",Max,sum);
sum=sum-max+1;
if(sum>=max) printf("Yes\n");
else printf("No\n");
}
return 0;
}

F

解法:模拟

#include <iostream>
#include<stdio.h>
using namespace std;
typedef struct stdust
{
char name[100];
int score;
} hehe;int main ()
{
int n,x,i,sum,zhang,d;
cin>>x;
{
while(x--)
{
cin >> n;
sum=0;
zhang=0;
hehe stdust[n];
for (int i=0; i<n; i++)
cin >> stdust[i].name >> stdust[i].score;
for(int i=0; i<n; i++)
{
if(stdust[i].score<=40)
sum+=1;
if(stdust[i].score>40)
{
if(stdust[i].score%40==0)
d=stdust[i].score/40;
else
d=stdust[i].score/40+1;
sum+=d;
zhang+=3;
} }
cout<<sum<<" "<<zhang<<endl;
}
}
}

G

解法:没有什么好说的

#include<stdio.h>
int main()
{
int n,a,sum;
while(scanf("%d",&n),n)
{
sum=0;
while(n--)
{
scanf("%d",&a);
sum+=a;
}
printf("%d\n",sum);
}
return 0;
}

H

解法:暂无(记忆化搜索??)

上一篇: 内存恶鬼drawRect
下一篇: hahaha
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,027
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,365
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,857