博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2014浙大校赛
阅读量:6197 次
发布时间:2019-06-21

本文共 9084 字,大约阅读时间需要 30 分钟。

ZOJ 3767 Elevator

求和,签到题

//#pragma comment(linker, "/STACK:1024000000,1024000000")#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair
pii;#define pb(a) push(a)#define INF 0x1f1f1f1f#define lson idx<<1,l,mid#define rson idx<<1|1,mid+1,r#define PI 3.1415926535898template
T min(const T& a,const T& b,const T& c) { return min(min(a,b),min(a,c));}template
T max(const T& a,const T& b,const T& c) { return max(max(a,b),max(a,c));}void debug() {#ifdef ONLINE_JUDGE#else freopen("in.txt","r",stdin); //freopen("d:\\out1.txt","w",stdout);#endif}int getch() { int ch; while((ch=getchar())!=EOF) { if(ch!=' '&&ch!='\n')return ch; } return EOF;}int main(){ int n,m; int t; scanf("%d",&t); for(int ca=1;ca<=t;ca++) { scanf("%d%d",&n,&m); int res=0; for(int i=0;i
View Code

ZOJ 3775 ?(>_o)!

题意中一大堆无用信息,其实就是判断源码和输出是否一样。简单字符串处理,string很方便

//#pragma comment(linker, "/STACK:1024000000,1024000000")#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair
pii;#define pb(a) push(a)#define INF 0x1f1f1f1f#define lson idx<<1,l,mid#define rson idx<<1|1,mid+1,r#define PI 3.1415926535898template
T min(const T& a,const T& b,const T& c) { return min(min(a,b),min(a,c));}template
T max(const T& a,const T& b,const T& c) { return max(max(a,b),max(a,c));}void debug() {#ifdef ONLINE_JUDGE#else freopen("in.txt","r",stdin); //freopen("d:\\out1.txt","w",stdout);#endif}int getch() { int ch; while((ch=getchar())!=EOF) { if(ch!=' '&&ch!='\n')return ch; } return EOF;}int main(){ int t; cin>>t; getchar(); for(int ca=1;ca<=t;ca++) { string s1; getline(cin,s1); string s2; for(int i=0;i
View Code

ZOJ 3770 Ranking System

按比例分等级,排序

//#pragma comment(linker, "/STACK:1024000000,1024000000")#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair
pii;#define pb(a) push(a)#define INF 0x1f1f1f1f#define lson idx<<1,l,mid#define rson idx<<1|1,mid+1,r#define PI 3.1415926535898template
T min(const T& a,const T& b,const T& c) { return min(min(a,b),min(a,c));}template
T max(const T& a,const T& b,const T& c) { return max(max(a,b),max(a,c));}void debug() {#ifdef ONLINE_JUDGE#else freopen("in.txt","r",stdin); //freopen("d:\\out1.txt","w",stdout);#endif}int getch() { int ch; while((ch=getchar())!=EOF) { if(ch!=' '&&ch!='\n')return ch; } return EOF;}struct number{ int id; string date; int score; int order; int lv; bool operator < (const number &ant) const { if(score!=ant.score)return score>ant.score; else if(date!=ant.date) return date
>t; for(int ca=1;ca<=t;ca++) { int n;cin>>n; for(int i=0;i
>da[i].id>>da[i].date>>da[i].score; da[i].order=i; } sort(da,da+n); int num=0; while(num
0)num++; int pre=0; int x=(int)(num*0.03); for(int i=pre;i
0;pre++) da[pre].lv=2; for(;pre
View Code

ZOJ 3768 Continuous Login

 将n分解为尽量少个前缀和,搜索,暴力出奇迹,我用的是迭代加深

//#pragma comment(linker, "/STACK:1024000000,1024000000")#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair
pii;#define pb(a) push(a)#define INF 0x1f1f1f1f#define lson idx<<1,l,mid#define rson idx<<1|1,mid+1,r#define PI 3.1415926535898template
T min(const T& a,const T& b,const T& c) { return min(min(a,b),min(a,c));}template
T max(const T& a,const T& b,const T& c) { return max(max(a,b),max(a,c));}void debug() {#ifdef ONLINE_JUDGE#else freopen("in.txt","r",stdin); //freopen("d:\\out1.txt","w",stdout);#endif}int getch() { int ch; while((ch=getchar())!=EOF) { if(ch!=' '&&ch!='\n')return ch; } return EOF;}const int maxn=40000;int f[maxn];int ans[maxn];int cal(int n){ int k=(int)(sqrt(n*2)+1); while(f[k]>n)k--; return k;}int dfs(int d,int n,int k){ if(k==1) { ans[k]=cal(n); if(n==f[cal(n)])return true; }else { for(int x=min(d,cal(n));x>=1;x--) { ans[k]=x; if(dfs(x,n-f[x],k-1))return true; } } return 0;}int main(){ for(int i=1;i
View Code

ZOJ 3772 Calculate the Function

做法1:线段树维护区间矩阵乘积,注意是左乘还是右乘

做法2:预处理出全部前缀矩阵乘积和全部前缀逆矩阵乘积(就跟区间和sum(b)-sum(a-1)一样)

线段树:

//#pragma comment(linker, "/STACK:1024000000,1024000000")#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair
pii;#define pb(a) push(a)#define INF 0x1f1f1f1f#define lson idx<<1,l,mid#define rson idx<<1|1,mid+1,r#define PI 3.1415926535898template
T min(const T& a,const T& b,const T& c) { return min(min(a,b),min(a,c));}template
T max(const T& a,const T& b,const T& c) { return max(max(a,b),max(a,c));}void debug() {#ifdef ONLINE_JUDGE#else freopen("in.txt","r",stdin); //freopen("d:\\out1.txt","w",stdout);#endif}int getch() { int ch; while((ch=getchar())!=EOF) { if(ch!=' '&&ch!='\n')return ch; } return EOF;}const int mod=1000000007;struct Matrix{ ll a[2][2]; Matrix(){memset(a,0,sizeof(a));} void set(ll A) { a[0][0]=a[1][0]=1; a[0][1]=A; a[1][1]=0; } void setI() { a[0][0]=a[1][1]=1; a[0][1]=a[1][0]=0; }};Matrix operator * (const Matrix &a,const Matrix &b){ Matrix res; for(int i=0;i<2;i++) for(int j=0;j<2;j++) for(int k=0;k<2;k++) res.a[i][j]=(res.a[i][j]+a.a[i][k]*b.a[k][j])%mod; return res;}const int maxn=100005;ll A[maxn];Matrix v[maxn<<2];void PushUp(int idx){ v[idx]=v[idx<<1|1]*v[idx<<1];}void build(int idx,int l,int r){ if(l==r) { v[idx].set(A[r]); }else { int mid=(r+l)>>1; build(lson); build(rson); PushUp(idx); }}Matrix query(int idx,int l,int r,int tl,int tr){ if(tl<=l&&tr>=r) return v[idx]; Matrix res; res.setI(); int mid=(r+l)>>1; if(tl<=mid) res=res*query(lson,tl,tr); if(tr>mid) res=query(rson,tl,tr)*res; return res;}ll cal(const Matrix &x,int a,int b){ return (x.a[0][0]*a+x.a[0][1]*b)%mod;}int main(){ int t; scanf("%d",&t); for(int ca=1;ca<=t;ca++) { int n,q; scanf("%d%d",&n,&q); for(int i=1;i<=n;i++) scanf("%lld",&A[i]); build(1,1,n); for(int Q=1;Q<=q;Q++) { int l,r; scanf("%d%d",&l,&r); ll res=0; if(r-l<2) res=A[r]; else { Matrix x=query(1,1,n,l+2,r); res=cal(x,A[l+1],A[l]); } printf("%lld\n",res); } } return 0;}
View Code

ZOJ 3769 Diablo III

背包,先把特殊的装备处理了,把任意一对Finger当成一件装备还有把Weapon 和Shield 的任意组合当成Two-Handed

然后就是普通的背包了,dp[i][j]表示装备前i类装备防御力为j的最大攻击力(j>=m的情况都当成是m)

需要优化:把攻击力和防御力都低的舍掉。

//#pragma comment(linker, "/STACK:1024000000,1024000000")#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair
pii;#define pb(a) push(a)#define INF 0x1f1f1f1f#define lson idx<<1,l,mid#define rson idx<<1|1,mid+1,r#define PI 3.1415926535898template
T min(const T& a,const T& b,const T& c) { return min(min(a,b),min(a,c));}template
T max(const T& a,const T& b,const T& c) { return max(max(a,b),max(a,c));}void debug() {#ifdef ONLINE_JUDGE#else freopen("in.txt","r",stdin); //freopen("d:\\out1.txt","w",stdout);#endif}int getch() { int ch; while((ch=getchar())!=EOF) { if(ch!=' '&&ch!='\n')return ch; } return EOF;}struct attri{ int a,b;};map
id;int ecnt;int ID(string s){ if(id.find(s)==id.end()) id[s]=++ecnt; return id[s];}vector
da[15];void deal(){ //combine weapon and shield int a=ID(string("Weapon")); da[a].push_back((attri){ 0,0}); int b=ID(string("Shield")); da[b].push_back((attri){ 0,0}); int c=ID(string("Two-Handed")); for(int i=0;i
buf; for(int i=0;i
>t; for(int ca=1;ca<=t;ca++) { int n,m; cin>>n>>m; ecnt=0; id.clear(); for(int i=1;i<=13;i++) da[i].clear(); for(int i=1;i<=n;i++) { string s; int a,b; cin>>s>>a>>b; int id=ID(s); da[id].push_back((attri){a,b}); } deal(); memset(dp,-1,sizeof(dp)); dp[0][0]=0;// for(int i=1;i<=13;i++)// {// cout<<"ID:"<
<
maxa&&da[i][j].b>maxb) { maxa=da[i][j].a;maxb=da[i][j].b; } for(int d=0;d<=m;d++)if(dp[i-1][d]!=-1) { int b=d+da[i][j].b; if(b>=m)b=m; dp[i][b]=max(dp[i][b],dp[i-1][d]+da[i][j].a); } } } cout<
<
View Code

 目前会做的只有这6题了。。

转载于:https://www.cnblogs.com/BMan/p/3649859.html

你可能感兴趣的文章
项目外包--程序员的来钱之道
查看>>
Ubuntu搜狗输入法的使用
查看>>
Dijkstra算法
查看>>
Led屏显示
查看>>
RecyclerView-- 侧滑删除和拖动排序
查看>>
Xutils, OKhttp, Volley, Retrofit对比
查看>>
关于Linux的iptables
查看>>
iphone 如何获取整个屏幕的大小
查看>>
Quartz的详解
查看>>
jQuery 1.9 .live() is not a function
查看>>
jquery mobile 移动web
查看>>
iOS ATS AFNetworking 单项认证
查看>>
SQL Server 2005之PIVOT/UNPIVOT行列转换
查看>>
去除浮动的新方法
查看>>
Django框架----视图(views)
查看>>
关于Promise的详细总结
查看>>
MySQL数据库----表与表之间的关系
查看>>
SpringBoot-08:SpringBoot采用json的方式实现前后台通用的配置文件
查看>>
javascript帧动画
查看>>
C# WCF的POST请求包含Stream及多个参数
查看>>