先定一个小目标:
51nod:基础题(5/5)1级题(5/5)2级题(5/5)3级题(5/5)4级题(5/5)
- 2017年10月23日
51nod1264
#include#include using namespace std;const double eps = 1e-8;class Point{public: double x, y; Point(double a=0, double b=0):x(a), y(b){}};int main(){ int T; cin>>T; while(T--) { Point p[5]; for(int i=0; i<4; ++i) cin>>p[i].x>>p[i].y; double v1 = (p[1].x-p[0].x)*(p[1].y-p[2].y)-(p[1].y-p[0].y)*(p[1].x-p[2].x);//p10 x p12 double v2 = (p[1].x-p[0].x)*(p[1].y-p[3].y)-(p[1].y-p[0].y)*(p[1].x-p[3].x);//p10 x p13 double v3 = (p[3].x-p[2].x)*(p[3].y-p[0].y)-(p[3].y-p[2].y)*(p[3].x-p[0].x);//p23 x p20 double v4 = (p[3].x-p[2].x)*(p[3].y-p[1].y)-(p[3].y-p[2].y)*(p[3].x-p[1].x);//p23 x p21 if((v1*v2<=0) && (v3*v4<=0)) cout<<"Yes"<
51nod1212
#include#include #define LL long longusing namespace std;const LL maxn = 1e3+3, INF = 2e9+7;int n, m;double grap[maxn][maxn];LL mst(){ LL res = 0; int dis[maxn]; bool vis[maxn]; for(int i=0; i<=n; ++i) { dis[i] = INF; vis[i]=false; } dis[1]=0; int u=1; for(int i=1; i<=n; ++i) { LL MinDis = INF; int v = u; for(int i=1; i<=n; ++i) { //cout< <<" "; if(!vis[i] && MinDis>dis[i]) { MinDis = dis[i]; v=i; } } vis[v]=true; u=v; //cout< grap[u][i]) { dis[i] = grap[u][i]; } } } return res;}int main(){ cin>>n>>m; for(int i=0; i<=n; ++i) for(int j=0; j<=n; ++j) { if(i==j) grap[i][j] = 0; else grap[i][j]=INF; } int u, v; double c; for(int i=0; i >u>>v>>c; grap[u][v]=min(grap[u][v], c); grap[v][u]=min(grap[v][u], c); } cout< <
- 2017年10月24日
51nod1183
#include#include #include using namespace std;const int maxn = 1e3+3, INF = 2e9+7;string a, b;int dp[maxn][maxn];int main(){ while(cin>>a>>b) { int la=a.size(), lb=b.size(); for(int i=0; i
51nod1181
#include#define LL long longusing namespace std;const int maxn = 1e7+6;LL prime[maxn] = { 0}, num_prime=0;int isNotPrime[maxn] = { 1, 1};int main(){ LL n; cin>>n; for(LL i=0; i =n && !isNotPrime[num_prime]) { cout< <
51nod1079
#include#define int long longusing namespace std;int Extended_Euclid(int a, int b, int &x, int &y){ int d; if(b==0) { x=1, y=0; return a; } d=Extended_Euclid(b, a%b, y, x); y-=a/b*x; return d;}int Chinese_Remainder(int a[], int w[], int len){ int i, d, x, y, m, n=1, ret=0; for(i=0; i >n) { for(int i=0; i >w[i]>>a[i]; cout<
- 2017年10月25日
51nod1305
#include#include #include #include #define int long longusing namespace std;vector a;int fun(vector & a){ sort(a.begin(), a.end()); int sum=0, tmp=0, la=a.size(); for(int i=0; i >n; for(int i=0; i >t; a.push_back(t); } cout< <
#include#include #define int long longusing namespace std;main(){ int n, t; cin>>n; int ans=0, two=0; for(int i=1; i<=n; ++i)//只有 1, 2 会对结果产生影响 { cin>>t; if(t==1) { ans+=n-1; } else if(t==2) { ans+=two; two++; } } cout< <
- 2017年10月28日
51nod1289
#include#include #include #include using namespace std;stack Stack;int main(){ int n; cin>>n; int cnt=n; for(int i=0; i >a>>b; if(b==1) Stack.push(a); else { while(!Stack.empty()) { if(a>Stack.top()) { cnt--; Stack.pop(); } else { cnt--; break; } } } } cout< <
51nod1283
#include#include #define LL long longusing namespace std;int main(){ LL s; cin>>s; LL a=sqrt(s); for(int i=a; i<=s; ++i) { if(s%i==0) { cout<<2*(i+s/i)<
51nod1182
#include#include #include #define LL long longusing namespace std;int sum[100];int main(){ memset(sum, 0, sizeof(sum)); string str; cin>>str; for(int i=0; i ='a'; --i) { ans+=(sum[i]*(i+1-'a')); } cout< <
- 2017年10月29日
51nod1091
#include#include #include #define int long longusing namespace std;class Line{public: int x, y; Line(int a, int b):x(a), y(b) { } bool operator < (const Line& l) { if(x==l.x) return y Lines;main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; int x, y; cin>>n; for(int i=0; i >x>>y; Lines.push_back(Line(x, y)); } sort(Lines.begin(), Lines.end()); int len = Lines.size(); int ans=0, pre=Lines[0].y; for(int i=1; i pre) { ans = max(ans, pre-Lines[i].x); pre=Lines[i].y; } else { ans = max(ans, Lines[i].y-Lines[i].x); } } cout< <
51nod1873
#include#include #include #include #include #define INF 1E9using namespace std;struct BigNum{ int len; int num[10000]; int point; BigNum() { len=1; point=0; memset(num,0,sizeof(num)); }};bool input(BigNum &a){ string s; if(cin>>s) { memset(a.num,0,sizeof(a.num)); int t=0,i; a.len=s.size(); a.point=0; for(i=s.size()-1;i>=0;i--) { if(s[i]=='.'){a.len--;a.point=t;continue;} a.num[t++]=s[i]-'0'; } return 1; } else return 0;}void output(BigNum &a){ int i,j=0,flag; for(i=0;i =0;i--) { cout< = 10) { c.num[i+j+1] += (int)c.num[i+j]/10; c.num[i+j] %= 10; } } c.point=a.point+b.point; len = a.len+b.len; while(c.num[len-1] == 0 && len > 1&&len>c.point) len--; if(c.num[len]) len++; c.len = len; return c;}BigNum a;int b;int main(){ while(input(a)&&~scanf("%d",&b)) { BigNum ans; if(b==0){cout<<1<
51nod1413
#includeusing namespace std;int main(){ string str; cin>>str; int ans=0; for(int i=0; i
51nod1432
#include#include #include #define int long longusing namespace std;const int maxn = 10005;int Weight[maxn];main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin>>n>>m; for(int i=0; i >Weight[i]; } int cnt=0; sort(Weight, Weight+n); int pre=0, las=n-1; while(pre<=las) { if(pre==las) { cnt++; break; } if(Weight[pre] + Weight[las] <= m) { pre++; las--; cnt++; } else { while(las>pre && (Weight[pre] + Weight[las] > m)) { las--; cnt++; } pre++; las--; cnt++; } } cout< <
51nod1428
#include#include #include #include #include #include #define int long longusing namespace std;const int maxn = 10004;class Line{public: int s, f; Line(int a=0, int b=0):s(a), f(b) { } bool operator < (const Line& l) const { if(this->f==l.f) return this->s>l.s; return this->f>l.f; }};vector lines;priority_queue PQ;bool vis[maxn];bool cmp(Line& a, Line& b){ if(a.s == b.s) return a.f >n; for(int i=0; i >s>>f; if(s>f) swap(s, f); lines.push_back(Line(s, f)); } sort(lines.begin(), lines.end(), cmp); int len = lines.size(); PQ.push(lines[0]); //cout<<"push: "< <<", "< <
- 2017年10月30日
51nod1315
#include#include #include #include #define int long longusing namespace std;const int maxn = 2e9+9;int binary[50];bool vis[50];int nums[50];int GetBinary(){ memset(binary, 0, sizeof(binary)); int val=1, i=0; while(val<=maxn) { binary[i]=val; i++; val<<=1; } return i;}main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int sum=GetBinary(); memset(vis, false, sizeof(vis)); memset(nums, 0, sizeof(nums)); int n, x, t, maxs=0; cin>>n>>x; for(int i=0; i >t; if((t|x)<=x) for(int i=0; i
51nod1636
#include#include #include #include #define int long longusing namespace std;const int maxn = 105, maxm = 105, maxk = 200;class Lesson{public: int a, b, c; Lesson(int x=0, int y=0, int z=0):a(x), b(y), c(z) { } bool operator < (const Lesson& l) const { return this->c lessons;int dp[maxn][maxm][maxk];main(){ int n, m, k; cin>>n>>m>>k; int a, b, c; for(int i=1; i<=m; ++i) { cin>>a>>b>>c; lessons.push_back(Lesson(a, b, c)); } sort(lessons.begin(), lessons.end()); memset(dp, -1, sizeof(dp)); for(int i=0; i = lessons[q].a && p-k <= lessons[q].b && dp[i-1][q][p-k-lessons[q].a]!=-1) { dp[i][j][p-lessons[j].a]=max(dp[i][j][p-lessons[j].a], dp[i-1][q][p-k-lessons[q].a] + p); } if(p%k==0 && p/k >= lessons[q].a && p/k<=lessons[q].b && dp[i-1][q][p/k-lessons[q].a]!=-1) { dp[i][j][p-lessons[j].a]=max(dp[i][j][p-lessons[j].a], dp[i-1][q][p/k-lessons[q].a] + p); } } } } } int ans = 0; for(int i=0; i
- 2017年10月31日
51nod1875
#include#define int long longusing namespace std;int ans[20]={ 0};int deal(int x){ for(int i=1; i<=1e7; ++i) { int all = 2*x; int s = 0; while(all>x) { s += (s==0?0:-1); s = (s+i)%all; if(s<=x && s!=0) break; all--; if(all == x) return i; } }}void init(){ ans[1]=1; for(int i=1; i<15; ++i) ans[i] = deal(i);}main(){ init(); int G; while(cin>>G && G!=0) { cout< <
51nod1572
#include#include #include #include using namespace std;const int maxn = 1e3+5;class Op{public: int dir, len; Op(int a=0, int b=0):dir(a), len(b) { }};char grap[maxn][maxn];int limit[maxn][maxn][5];//每个点四个方向的最大值int dir[4][2] = { {-1, 0}, { 1, 0}, { 0, 1}, { 0, -1} };//上下右左int word[30][3];vector ops;bool check(int w, int n, int m){ int x=word[w][1], y=word[w][2]; for(int i=0; i = limit[x][y][item.dir]) return false; x+=item.len * dir[item.dir][0], y+=item.len * dir[item.dir][1]; if(x<0 || y<0 || x>n || y>m || grap[x][y]=='#') return false; } return true;}main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); memset(word, -1, sizeof(word)); int n, m, k, pre=0; cin>>n>>m; for(int i=0; i >grap[i]; pre=0; for(int j=0; j ='A' && grap[i][j]<='Z') { word[int(grap[i][j]-'A')][0] = 1; word[int(grap[i][j]-'A')][1] = i; word[int(grap[i][j]-'A')][2] = j; } if(grap[i][j] == '#') { pre=j; } else { limit[i][j][3]=abs(j-pre); } } pre=0; for(int j=m-1; j>=0; --j) { if(grap[i][j] == '#') { pre=j; } else { limit[i][j][2]=abs(j-pre); } } } for(int j=0; j =0; --i) { if(grap[i][j] == '#') { pre=i; } else { limit[i][j][1]=abs(i-pre); } } } cin>>k; char d; int l; for(int i=0; i >d>>l; switch(d) { case 'N':ops.push_back(Op(0, l));break; case 'S':ops.push_back(Op(1, l));break; case 'E':ops.push_back(Op(2, l));break; case 'W':ops.push_back(Op(3, l));break; } } bool can = false; for(int i=0; i<26; ++i) { if(word[i][0]!=-1) { if(check(i, n, m)) { cout<
51nod1562
#include#include #include #include #include #define int long long#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1;using namespace std;const int maxn = 200005;class Point{public: int LeftPos, RightPos, LeftLen; Point(int lp=0, int rp=0, int ll=0):LeftPos(lp),RightPos(rp),LeftLen(ll) { }};vector is;vector cs;int wline[maxn], hline[maxn];Point wpoint[maxn], hpoint[maxn];main(){ int w, h, n, x; char op; memset(wline, 0, sizeof(wline)); memset(hline, 0, sizeof(hline)); cin>>w>>h>>n; for(int i=0; i >op>>x; cs.push_back(op); is.push_back(x); if(op=='H') { hline[x]=1; } else { wline[x]=1; } } hline[0]=wline[0]=hline[h]=wline[w]=1; int maxh=0, maxw=0; for(int i=0, pre=0; i<=w; ++i) { if(wline[i]) { maxw=max(maxw, i-pre); wpoint[pre].RightPos=i; wpoint[i]=Point(pre, i, i-pre); pre=i; } } for(int i=0, pre=0; i<=h; ++i) { if(hline[i]) { maxh=max(maxh, i-pre); hpoint[pre].RightPos=i; hpoint[i]=Point(pre, i, i-pre); pre=i; } } //cout<<"maxw: "< <<"maxh: "< <