T1: JerryC Loves Driving
第一题应该就是一道水分题(然而我只水了130分),我的主要做法就是暴力模拟,再做一些小小的优化(蠢得我自己都不想说了)。
My Code:
#includeusing namespace std;int a,b,ans;void read(int &x){ char ch; bool ok; for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1; for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;}void work(){ ans=0; read(a),read(b); for(int i=0;i<=b-a;i++){ int re=0; for(int j=1;j<=(a+i)/2;j++){ int k=(a+i)/j; if(j%2==0)re+=k; else re-=k; } if((a+i-(a+i)/2)%2!=0){ if(((a+i)/2)%2==0)re--; else re++; } ans+=re; } printf("%d\n",ans);}int main(){ work(); return 0;}
T2: Jerry Loves Lines
看了一眼后就开始暴力了,懒得去写更优的办法(其实就是我弱而已),结果悲剧的拿了64分。
My Code:
#include#define ll long longusing namespace std;ll n,m,k,val[2001];struct f{ ll k,b;}fct[2001];void read(ll &x){ char ch; bool ok; for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1; for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;}void work(ll x){ for(int i=1;i<=n;i++)val[i]=fct[i].k*x+fct[i].b; sort(val+1,val+n+1); printf("%lld\n",val[k]);}int main(){ read(n),read(m),read(k); for(int i=1;i<=n;i++)read(fct[i].k),read(fct[i].b); for(int i=1;i<=m;i++){ ll x;read(x); work(x); } return 0;}
T3: Samcompu Loves Water
这道题一开始我用的就是简单的子父链建树,在搜索,然而只A了三个点,于是我就开始思考更优的解法。然后我就想到了用并查集做这道题,然后,多A了两个点。。。
My Code:
#include#define ll long long#define N 1000001using namespace std;int n,m,fa[N],apr[N];ll sz[N];inline void read(int &x){ int f=1;x=0;char ch; do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9'); do{ x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9'); x*=f;}struct Line{ int from,to,val;}tree[N];int gf(int X){ if(fa[X]!=X)fa[X]=gf(fa[X]); return fa[X];}void work(int tim,int x){ ll ans=0; for(int i=1;i<=n;i++)apr[i]=0,sz[i]=1,fa[i]=i; for(int i=1;i =tim||i==x)continue; int f1=gf(tree[i].from),f2=gf(tree[i].to); if(f1==f2)continue; fa[f1]=f2; sz[f2]+=sz[f1]; } for(int i=1;i<=n;i++) if(i!=x&&!apr[gf(i)]){apr[gf(i)]=1;ans+=sz[gf(i)]*(sz[gf(i)]-1);}// for(int i=1;i<=n;i++)printf("Water: F: %d %d\n",gf(i),sz[gf(i)]); printf("%lld\n",ans);}int main(){ read(m),read(n); for(int i=1;i
T4: Zrz_orz Loves Secondary Element
看到有人对我老婆存在念想,我就没有了写题的欲望!!!(不会写)