nenu contest3 The 5th Zhejiang Provincial Collegiate Programming Contest
ZOJ Problem Set - 2965 Accurately Say "CocaCola"! http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2965
打表。求含有7或者是7的倍数的数。题目输入p,输出第一个连续出现p个满足条件的头。
#include<cstdio>
#include<cstring>
#include<algorithm>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const int M=;
bool vis[M];
bool isgood(int x){
while(x){
if(x%==) return true;
x/=;
}
return false;
}
int ans[M];
int main(){
mt(vis,);
for(int i=;i<M;i++){
if(isgood(i)||!(i%)){
vis[i]=true;
}
}
for(int i=;i<=;i++){
ans[i]=M;
}
int s=,t=;
for(int i=;i<M;i++){
if(!vis[i]){
s=t=i;
}
else{
t++;
ans[t-s]=min(ans[t-s],s+);
}
}
int n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
printf("%d\n",ans[n]);
}
return ;
}
ZOJ Problem Set - 2966 Build The Electric System http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2966
最小生成树 prim
#include<cstdio>
const int inf=0x3f3f3f3f;
class Prim { ///最小生成树(无向图)o(MV^2)要保证图连通
typedef int typec;///边权的类型
static const int MV=;///点的个数
int n,i,j,k,pre[MV];///pre[]返回树的构造,用父结点表示,根节点(第一个)pre值为-1
bool vis[MV];
typec mat[MV][MV],dist[MV],res;
public:
void init(int tn) { ///传入点数,点下标0开始
n=tn;
for(i=; i<n; i++)
for(j=; j<n; j++)
mat[i][j]=i==j?:inf;///不相邻点边权inf
}
void add(int u,int v,typec w) {
if(mat[u][v]>w) {
mat[u][v]=w;
mat[v][u]=w;
}
}
typec solve() { ///返回最小生成树的长度
for(res=i=; i<n; i++) {
dist[i]=inf;
vis[i]=false;
pre[i]=-;
}
for(dist[j=]=; j<n; j++) {
for(k=-,i=; i<n; i++) {
if(!vis[i]&&(k==-||dist[i]<dist[k])) {
k=i;
}
}
for(vis[k]=true,res+=dist[k],i=; i<n; i++) {
if(!vis[i]&&mat[k][i]<dist[i]) {
dist[i]=mat[pre[i]=k][i];
}
}
}
return res;
}
}gx;
int main(){
int t,n,m,u,v,w;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
gx.init(n);
while(m--){
scanf("%d%d%d",&u,&v,&w);
gx.add(u,v,w);
}
printf("%d\n",gx.solve());
}
return ;
}
Kruskal
#include<cstdio>
#include<cstring>
#include<algorithm>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const int inf=0x3f3f3f3f;
class Kruskal { ///最小生成树(无向图)o(ME*logME)
typedef int typec;///边权的类型
static const int ME=*;///边的个数
static const int MV=;///点的个数
class UnionFindSet { ///并查集
int par[MV];
public:
void init() {
mt(par,-);
}
int getroot(int x) {
int i=x,j=x,temp;
while(par[i]>=) i=par[i];
while(j!=i) {
temp=par[j];
par[j]=i;
j=temp;
}
return i;
}
bool unite(int x,int y) {
int p=getroot(x);
int q=getroot(y);
if(p==q)return false;
if(par[p]>par[q]) {
par[q]+=par[p];
par[p]=q;
} else {
par[p]+=par[q];
par[q]=p;
}
return true;
}
} f;
struct E {
int u,v;
typec w;
friend bool operator < (E a,E b) {
return a.w<b.w;
}
} e[ME];
int le,num,n;
typec res;
public:
void init(int tn){///传入点的个数
n=tn;
le=res=;
f.init();
num=;
}
void add(int u,int v,typec w) {
e[le].u=u;
e[le].v=v;
e[le].w=w;
le++;
}
typec solve(){///返回-1不连通
sort(e,e+le);
for(int i=; i<le&&num<n; i++) {
if(f.unite(e[i].u,e[i].v)) {
num++;
res+=e[i].w;
}
}
if(num<n) res=-;
return res;
}
}gx;
int main(){
int t,n,m,u,v,w;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
gx.init(n);
while(m--){
scanf("%d%d%d",&u,&v,&w);
gx.add(u,v,w);
}
printf("%d\n",gx.solve());
}
return ;
}
ZOJ Problem Set - 2969 Easy Task http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1968
给式子的系数,求导完输出系数,如果全为零输出零,否则从第一个不为零的开始输出。
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=;
int a[M];
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=n;i>=;i--){
scanf("%d",&a[i]);
}
int id=-;
for(int i=n;i>=;i--){
a[i]*=i;
if(a[i]){
id=max(id,i);
}
}
if(id==-){
puts("");
continue;
}
for(int i=id;i>=;i--){
if(i!=id) printf(" ");
printf("%d",a[i]);
}
puts("");
}
return ;
}
ZOJ Problem Set - 2970 Faster, Higher, Stronger http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1969
f就找最小,其他找最大。
#include<cstdio>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
int main(){
int t,n,a;
scanf("%d",&t);
char op[];
while(t--){
scanf("%s%d",op,&n);
bool sma=false;
int ans=-inf;
if(op[]=='F'){
sma=true;
ans=inf;
}
for(int i=;i<n;i++){
scanf("%d",&a);
if(sma){
ans=min(ans,a);
}
else{
ans=max(ans,a);
}
}
printf("%d\n",ans);
}
return ;
}
ZOJ Problem Set - 2971 Give Me the Number http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1970
3个3个处理,然后加起来。
#include<cstdio>
#include<cstring>
const int M=;
char a[M*M],b[M][M];
int ans[M],val[M];
char gewei[M][M]={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
char shiwei[M][M]={"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
char jishi[M][M]={"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
int main(){
int t;
scanf("%d",&t);
getchar();
while(t--){
gets(a);
int cnt=,lb=;
for(int i=;a[i];i++){
if(a[i]==' '){
b[cnt][lb]=;
cnt++;
lb=;
}
else{
b[cnt][lb++]=a[i];
}
}
b[cnt][lb]=;
cnt++;
for(int i=;i<=;i++){
ans[i]=;
val[i]=;
}
int sta=;
for(int i=cnt-;i>=;i--){
if(!strcmp(b[i],"and")) continue;
int now=-;
for(int j=;j<;j++){
if(!strcmp(b[i],gewei[j])){
now=j;
break;
}
}
if(now==-){
for(int j=;j<;j++){
if(!strcmp(b[i],shiwei[j])){
now=j+;
break;
}
}
}
if(now==-){
for(int j=;j<;j++){
if(!strcmp(b[i],jishi[j])){
now=(j+)*;
break;
}
}
}
if(~now){
ans[sta]+=now*val[sta];
}
else{
if(!strcmp(b[i],"hundred")){
val[sta]=;
continue;
}
if(!strcmp(b[i],"thousand")){
sta=;
continue;
}
if(!strcmp(b[i],"million")){
sta=;
continue;
}
}
}
int sum=;
for(int i=;i<=;i++){
sum*=;
sum+=ans[i];
}
printf("%d\n",sum);
}
return ;
}
ZOJ Problem Set - 2972 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1971
dp i j 表示第 i 个位置 还剩 j 的体力 能获得的最小时间,有三种方式转移,根据题目输入来转移。用t1就要浪费f1 用t2不变, 用t3还能挣点体力,注意体力上限m
#include<cstdio>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
const int M=;
struct G{
int T1,T2,T3,F1,F2;
}sta[M];
int dp[M][M];
int main(){
int t,n,m;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
scanf("%d%d%d%d%d",&sta[i].T1,&sta[i].T2,&sta[i].T3,&sta[i].F1,&sta[i].F2);
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
dp[i][j]=inf;
}
}
dp[][m]=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(j>=sta[i+].F1){
dp[i+][j-sta[i+].F1]=min(dp[i+][j-sta[i+].F1],dp[i][j]+sta[i+].T1);
}
dp[i+][j]=min(dp[i+][j],dp[i][j]+sta[i+].T2);
dp[i+][min(m,j+sta[i+].F2)]=min(dp[i+][min(m,j+sta[i+].F2)],dp[i][j]+sta[i+].T3);
}
}
int ans=inf;
for(int j=;j<=m;j++){
ans=min(ans,dp[n][j]);
}
printf("%d\n",ans);
}
return ;
}
ZOJ Problem Set - 2975 Kinds of Fuwas http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1974
求四个角相等的矩形个数。n^3的做法。枚举两列n^2,on枚举这两列有几对一样的,然后他们可以组成C n选2 种矩形。
#include<cstdio>
typedef long long LL;
const int M=;
char a[M][M];
char cp[]={'B','J','H','Y','N'};
int main(){
int t,n,m;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
for(int i=;i<n;i++){
scanf("%s",a[i]);
}
LL ans=;
for(int k=;k<;k++){
for(int x=;x<m;x++){
for(int y=x+;y<m;y++){
LL sum=;
for(int i=;i<n;i++){
if(cp[k]==a[i][x]&&cp[k]==a[i][y]){
sum++;
}
}
ans+=sum*(sum-)/;
}
}
}
printf("%lld\n",ans);
}
return ;
}
ZOJ Problem Set - 2976 Light Bulbs http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1975
因为是格点,整点,所以200*200枚举点,对每个点枚举灯算总和。4*10^6*case
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int M=;
struct point3 {
double x,y,z,I;
} p[M],now;
double Distance(point3 p1,point3 p2) {
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z));
}
int main() {
int t,n;
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z,&p[i].I);
}
double ans=;
for(int x=-;x<=;x++){
for(int y=-;y<=;y++){
now.x=x;
now.y=y;
now.z=;
double sum=;
for(int i=;i<n;i++){
double dist=Distance(now,p[i]);
sum+=p[i].I*p[i].z/dist/dist/dist;
}
ans=max(ans,sum);
}
}
printf("%.2f\n",ans);
}
return ;
}
end
nenu contest3 The 5th Zhejiang Provincial Collegiate Programming Contest的更多相关文章
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest May Day Holiday
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5500 The 12th Zhejiang Provincial ...
- 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(第二部分)
Floor Function Time Limit: 10 Seconds Memory Limit: 65536 KB a, b, c and d are all positive int ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Convert QWERTY to Dvorak
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5502 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Demacia of the Ancients
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5504 The 12th Zhejiang Provincial ...
- zjuoj The 12th Zhejiang Provincial Collegiate Programming Contest Ace of Aces
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5493 The 12th Zhejiang Provincial ...
随机推荐
- linux中Apache更Nginx环境配置教程
想把Apache2.2换Nginx已经有些日子,今天给动手了.找了个稳定版本:1.4.1 http://nginx.org/download/nginx-1.4.1.zip 配置很简单,就是ngin ...
- java中serializable
java中serializable是一个对象序列化的接口,一个类只有实现了Serializable接口,它的对象才是可序列化的.因此如果要序列化某些类的对象,这些类就必须实现Serializable接 ...
- UI1_UINavigationController
// // FourthViewController.h // UI1_UINavigationController // // Created by zhangxueming on 15/7/6. ...
- webSphere提示SSL证书过期,解决方法
1.点击Security ------SSL certificate and key management2.点击Related Items下的key stores and certificates3 ...
- HyperMesh生成Flac3D的剖分网格
本帖的目的是探索煤矿沉积岩层采煤过程中的力学分析模拟的前处理方法,计算软件采用公认的Flac3D差分方法. 目前,Flac3D官方提供的剖分网格的生成方法有三种.一是直接使用命令和Fish语句生成,这 ...
- C++ Strings(字符串)
Constructors 构造函数,用于字符串初始化 Operators 操作符,用于字符串比较和赋值 append() 在字符串的末尾添加文本 assign() 为字符串赋新值 at() 按给定索引 ...
- Java通过代理类实现数据库DAO操作
下面的所有代码示例都取自李兴华的<Java Web开发实战经典>的随书源码,因为觉得设计得很好,所以将代码摘录下来作成笔记. 首先,我们在一个java文件中定义要存储的结构类型: impo ...
- Java RMI 远程方法调用
Java RMI 指的是远程方法调用 (Remote Method Invocation).它是一种机制,能够让在某个 Java 虚拟机上的对象调用另一个 Java 虚拟机中的对象上的方法.可以用此方 ...
- C#学习笔记(第1周作业)
受队友诱惑,去听了李强的C#公选课,第二天就完成作业了. 作业要求: 1. 小学生加法程序: 2. 能自由设置难度: 3. 对结果进行统计. 第一次写C#程序,遇到不少困难,和队友讨论,百度谷歌一齐上 ...
- js 字符串“123”,变成整数123,不用parseInt 函数
var s = "123"; console.log(s.charAt(0)*100+s.charAt(1)*10+s.charAt(2)*1);