水题,模拟题,但仍需细心,多考虑
//http://codeforces.com/contest/1065/problem/B
#include <iostream> #include <cmath> using namespace std; int main() { long long n,m,num,s,a,b,c,minIS,maxIS; cin>>n>>m; if(n<2*m) { minIS=0; } else { minIS=n-2*m; } if(m==2) { maxIS=n-3; } else if(m==0) { maxIS=n; } else { maxIS=n-(1+(sqrt(1+8*m)))/2; } cout<<minIS<<" "<<maxIS<<endl; return 0; }
http://codeforces.com/contest/1065/problem/C
真的水,题目水,我也水。最终只能用暴力ac掉 刚开始突发奇想从下面往上面考虑,但其实这样是与题目做法不是完全一致的。所以还是模拟好了
long long h[200000]; long long n,k; int main() { cin>>n>>k; for(int i=0; i<n; i++) { cin>>h[i]; } sort(h,h+n,cmp); long long head=0,sum=0,countt=0,pos=0; for(int i=1;i<n;i++) { for(int j=h[i];j<h[i-1];j++) //遍历这两层之间的每一层 { if(sum+i<=k) { sum+=i; } else { sum=i; countt++; } } } if(sum>0) countt++; cout<<countt<<endl; return 0; }
https://www.luogu.org/problemnew/show/P1064
1. 思路见题解
2. 之前
bage01(int C,int V,int W,int id) 传了个 i ,和for循环的i重复了这个错误一直没有发现。所以说变量的命名十分重要啊摔
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #define MAX 100005 using namespace std; int N,m,v[MAX],p[MAX],f[MAX],q[MAX]; bool visit[MAX]; vector<int> a[MAX]; void bage01(int C,int V,int W,int id)//C now weight, v total weight,w value { for(int i=V; i>=C; i--) { f[i]=max(f[i],f[i-C]+W); int sump=0,sumv=0; for(int k=0;k<a[id].size();k++) { sump+=p[a[id][k]]; sumv+=v[a[id][k]]; if(i-C-v[a[id][k]]>=0) f[i]=max(f[i],f[i-C-v[a[id][k]]]+W+p[a[id][k]]); } if(i-sumv-C>=0) f[i]=max(f[i],f[i-sumv-C]+W+sump); } } void solve() { for(int i=1; i<=m; i++) { if(q[i]==0) { bage01(v[i],N,p[i],i); } } } int main() { cin>>N>>m; for(int i=1; i<=m; i++) { cin>>v[i]>>p[i]>>q[i]; p[i]=p[i]*v[i]; if(q[i]>0){ a[q[i]].push_back(i); } //cin>>v[i]>>p[i]; } solve(); cout<<f[N]<<endl; return 0; }