-
Bio
ICPC 2017 T9
雷霆代码+雷霆特判 未来100年内无人读懂的AC代码(笑)
#include <bits/stdc++.h> using namespace std; bool b[40][40]; int lx,ly,lx2,ly2; void cr(int n,int twd,int x,int y) { if(twd==0) { if(b[x+2][y])return ; int i; for(i=x;i<n;i++) { b[i][y]=1; if(b[i+2][y]) break; } lx2=lx,ly2=ly; lx=i;ly=y; cr(n,1,i,y); } if(twd==1) { if(b[x][y+2])return ; int i; for(i=y;i<n;i++) { b[x][i]=1; if(b[x][i+2]) break; } lx2=lx,ly2=ly; lx=x;ly=i; cr(n,2,x,i); } if(twd==2) { if(x-2==-1) { return ; } if(b[x-2][y]) { return ; } int i; for(i=x;i>1;i--) { b[i][y]=1; if(i-2==-1) { break; } if(b[i-2][y]) { break; } } lx2=lx,ly2=ly; lx=i;ly=y; cr(n,3,i,y); } if(twd==3) { if(y-2==-1) { return ; } if(b[x][y-2]) { return ; } int i; for(i=y;i>1;i--) { b[x][i]=1; if(i-2==-1) { break; } if(b[x][i-2]) { break ; } } lx2=lx,ly2=ly; lx=x;ly=i; if(n==4)return; cr(n-2,0,x,i); } } void s() { memset(b,0,sizeof(b)); } void a(int n) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(b[j][i]) { cout<<"#"; } else cout<<" "; } cout<<endl; } } int main() { int t,n; cin>>t; while(t--) { cin>>n; if(n==1){ printf("#\n"); continue; } if(n==2){ printf("##\n #\n"); continue; } if(n==3){ printf("###\n #\n###\n"); continue; } s(); cr(n,0,1,1); if(n%2==0&&n!=4)b[lx2][ly2]=0; if(n>=10&&n%4==2){ b[lx2][ly2]=1; b[lx2][ly2+1]=0; } if((n-1)%4==0){ b[n/2+1][n/2+1]=1; } a(n); } return 0; }woc! 我做出正解了!
#include <bits/stdc++.h> using namespace std; bool rect[100][100]; void summon(int& n,int lv,int twd,int x,int y){ if(lv>n)return; if(twd==1){ int dx=x; for(int i=1;i<=n-(lv-2)/2*2;i++){ rect[dx++][y]=1; } summon(n,lv+1,2,dx-1,y); } if(twd==2){ int dy=y; for(int i=1;i<=n-(lv-2)/2*2;i++){ rect[x][dy++]=1; } summon(n,lv+1,3,x,dy-1); } if(twd==3){ int dx=x; for(int i=1;i<=n-(lv-2)/2*2;i++){ rect[dx--][y]=1; } summon(n,lv+1,4,dx+1,y); } if(twd==4){ int dy=y; for(int i=1;i<=n-(lv-2)/2*2;i++){ rect[x][dy--]=1; } summon(n,lv+1,1,x,dy+1); } } void print(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(rect[j][i])printf("#"); else printf(" "); } printf("\n"); } } int main(){ int t,n; scanf("%d",&t); while(t--){ scanf("%d",&n); memset(rect,0,sizeof(rect)); summon(n,1,1,1,1); print(n); } return 0; }T782766 [入门赛 #49]
#include<bits/stdc++.h> #define lol long long using namespace std; const lol N=1e11; lol n,ans; int main(){ scanf("%lld",&n); for(int x=1;x<=36;x++){ for(int y=1;y<=316227;y++){ if((1ll<<x)+1ll*y*y<=n){ ans++; } } } printf("%lld",ans); return 0; }#p1718. 习题1.2.8 扫雷游戏
#include<windows.h> #include<stdio.h> #include<stdlib.h> #include<time.h> #include<conio.h> #define color(attr); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x##attr); #define gotoxy(x,y); SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),{x,y}); int rect[18][18]; bool mark[18][18]; bool vis[18][18]; int vis_quantity; bool found; void init_rect(){ srand((unsigned int)(time(NULL))); for(int i=256;i>216;i--){ int tmp=rand()%i; bool flag=0; for(int j=1;j<=16&&!flag;j++){ for(int k=1;k<=16&&!flag;k++){ if(rect[j][k]>=1000)continue; if(tmp--)continue; rect[j-1][k-1]++; rect[j-1][k]++; rect[j-1][k+1]++; rect[j][k-1]++; rect[j][k]=1000; rect[j][k+1]++; rect[j+1][k-1]++; rect[j+1][k]++; rect[j+1][k+1]++; flag=1; } } } for(int i=1;i<=16;i++){ for(int j=1;j<=16;j++){ if(rect[i][j]>=1000)rect[i][j]=1000; } } for(int i=0;i<18;i++){ rect[i][0]=-1; rect[0][i]=-1; rect[i][17]=-1; rect[17][i]=-1; vis[i][0]=1; vis[0][i]=1; vis[i][17]=1; vis[17][i]=1; } } bool GetConsoleWordSize(int &width,int &height){ HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE); if(hConsole==INVALID_HANDLE_VALUE)return false; _CONSOLE_FONT_INFO cfi; if(!GetCurrentConsoleFont(hConsole,0,&cfi))return false; width=cfi.dwFontSize.X; height=cfi.dwFontSize.Y; return true; } bool GetConsoleMousePos(HWND hClientWnd,LPPOINT lpPoint,int nWidth,int nHeight){ if(!GetCursorPos(lpPoint))return 0; if(!ScreenToClient(hClientWnd,lpPoint))return 0; lpPoint->x/=nWidth;lpPoint->y/=nHeight; return 1; } void detect(int x,int y){ vis[x][y]=1; vis_quantity++; mark[x][y]=0; if(rect[x][y]){ if(rect[x][y]==1000)found=1; return; } if(!vis[x-1][y-1])detect(x-1,y-1); if(!vis[x-1][y])detect(x-1,y); if(!vis[x-1][y+1])detect(x-1,y+1); if(!vis[x][y-1])detect(x,y-1); if(!vis[x][y+1])detect(x,y+1); if(!vis[x+1][y-1])detect(x+1,y-1); if(!vis[x+1][y])detect(x+1,y); if(!vis[x+1][y+1])detect(x+1,y+1); } void DisableConsoleSelect(){ HANDLE hIn=GetStdHandle(STD_INPUT_HANDLE); DWORD Mode; GetConsoleMode(hIn,&Mode); SetConsoleMode(hIn,Mode&(~ENABLE_QUICK_EDIT_MODE)&(~ENABLE_MOUSE_INPUT)); } bool HideConsoleCursor(){ HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cci; GetConsoleCursorInfo(hOut,&cci); cci.bVisible=FALSE; return (bool)SetConsoleCursorInfo(hOut,&cci); } void print(){ for(int i=1;i<=16;i++){ for(int j=1;j<=16;j++){ if(vis[i][j]){ gotoxy(i*2,j); if(rect[i][j]==0){color(8);putchar('0');color(7);} else if(rect[i][j]==1){color(1);putchar('1');color(7);} else if(rect[i][j]==2){color(2);putchar('2');color(7);} else {color(4);printf("%d",rect[i][j]);color(7);} }else if(mark[i][j]){ color(C); gotoxy(i*2,j); putchar('P'); color(7); }else{ gotoxy(i*2,j); color(8); putchar('-'); color(7); } } } } void last_print(){ for(int i=1;i<=16;i++){ for(int j=1;j<=16;j++){ if(mark[i][j]&&rect[i][j]!=1000){ color(d); gotoxy(i*2,j); putchar('F'); color(7); }else if(rect[i][j]==1000){ if(vis[i][j]){color(47);}else{color(F);} gotoxy(i*2,j); putchar('X'); } } } } const char str_data[11][1024]={ {84,73,84,76,69,32,-33,-9,-33,-9,-33,-9}, {-54,-13,-79,-22,-42,-72,-43,-21,-50,-69,-42,-61,-93,-70,-60,-29,-47,-95,-42,-48,-75,-60,-50,-69,-42,-61,-95,-93,10,-41,-13,-68,-4,-93,-70,-52,-67,-78,-30,-95,-93,10,-65,-43,-72,-15,-93,-70,-79,-22,-68,-57,-95,-93}, {-79,-16,-50,-54,-50,-46,-50,-86,-55,-74,-78,-69,-54,-57,-45,-46,-68,-4,-79,-22,-68,-57,-93,-84,-60,-29,-41,-44,-68,-70,-65,-76,-65,-76,-45,-46,-68,-4,-77,-10,-64,-76,-63,-53,-55,-74,-95,-93}, {-79,-22,-76,-19,-50,-86,-95,-80}, {-95,-79}, {80,65,85,83,69}, {67,76,83}, {-60,-29,-54,-89,-80,-36,-63,-53,-93,-95}, {-54,-92,-64,-5,-93,-95}, {43,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,43}, {124,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,124}, }; int main(){ DisableConsoleSelect(); system(str_data[0]); puts(str_data[1]); color(8); puts(str_data[2]); color(7); printf(str_data[3]); color(d); putchar('F'); color(7); puts(str_data[4]); color(2); system(str_data[5]); color(7); system(str_data[6]); int w,h; HWND hConsole=GetConsoleWindow(); init_rect(); POINT mouse; puts(str_data[9]); for(int i=1;i<=16;i++)puts(str_data[10]); puts(str_data[9]); while(true){ print(); if(!GetConsoleWordSize(w,h))continue; if(!HideConsoleCursor())continue; if(GetAsyncKeyState(VK_LBUTTON)){ if(!GetConsoleMousePos(hConsole,&mouse,w,h))continue; if(1>mouse.x/2||mouse.x/2>16||1>mouse.y||mouse.y>16)continue; if(vis[mouse.x/2][mouse.y]||mark[mouse.x/2][mouse.y])continue; detect(mouse.x/2,mouse.y); }else if(kbhit()){ if(getch()!=' ')continue; if(!GetConsoleMousePos(hConsole,&mouse,w,h))continue; if(vis[mouse.x/2][mouse.y])continue; if(1>mouse.x/2||mouse.x/2>16||1>mouse.y||mouse.y>16)continue; mark[mouse.x/2][mouse.y]=!mark[mouse.x/2][mouse.y]; } if(found){ last_print(); gotoxy(1,18); color(47); puts(str_data[7]); color(7); Sleep(-1); } if(vis_quantity==216){ gotoxy(1,18); color(a7); puts(str_data[8]); color(7); Sleep(-1); } Sleep(6); } return 0; }666,在讨论里翻到高精度了(美式震惊)
#include<bits/stdc++.h> using namespace std; struct superint { vector<long long> digits; bool isNegative=false; superint() { digits.push_back(0); } superint(const string& s) { long long start=0; if(s[0]=='-') { isNegative=true; start=1; } for(long long i=s.length()-1;i>=start;i--) { if(isdigit(s[i])) digits.push_back(s[i]-'0'); } removeLeadingZeros(); } superint(long long num) { if(num<0) { isNegative=true; num=-num; } if(num==0) { digits.push_back(0); } while(num>0) { digits.push_back(num%10); num/=10; } removeLeadingZeros(); } void removeLeadingZeros() { while(digits.size()>1&&digits.back()==0) digits.pop_back(); if(digits.size()==1&&digits[0]==0) isNegative=false; } long long compareAbs(const superint& other) const { if(digits.size()!=other.digits.size()) return digits.size()>other.digits.size()?1:-1; for(long long i=digits.size()-1;i>=0;i--) { if(digits[i]!=other.digits[i]) return digits[i]>other.digits[i]?1:-1; } return 0; } superint abs() const { superint result=*this; result.isNegative=false; return result; } bool operator<(const superint& other) const { if(isNegative!=other.isNegative) return isNegative; if(isNegative) return compareAbs(other)>0; else return compareAbs(other)<0; } bool operator<=(const superint& other) const { return !(other<*this); } bool operator>(const superint& other) const { return other<*this; } bool operator>=(const superint& other) const { return !(*this<other); } bool operator==(const superint& other) const { return isNegative==other.isNegative&&digits==other.digits; } bool operator!=(const superint& other) const { return !(*this==other); } superint operator+(const superint& other) const { if(isNegative!=other.isNegative) { if(isNegative) return other-(-*this); else return *this-(-other); } superint result; result.isNegative=isNegative; result.digits.clear(); long long carry=0; long long maxSize=max(digits.size(),other.digits.size()); for(long long i=0;i<maxSize||carry;i++) { long long sum=carry; if(i<digits.size()) sum+=digits[i]; if(i<other.digits.size()) sum+=other.digits[i]; result.digits.push_back(sum%10); carry=sum/10; } result.removeLeadingZeros(); return result; } superint& operator+=(const superint& other) { *this=*this+other; return *this; } superint operator-(const superint& other) const { if(isNegative!=other.isNegative) return *this+(-other); if(isNegative) return (-other)-(-*this); if(*this<other) return -(other-*this); superint result; result.digits.clear(); long long borrow=0; for(long long i=0;i<digits.size();i++) { long long diff=digits[i]-borrow; if(i<other.digits.size()) diff-=other.digits[i]; if(diff<0) { diff+=10; borrow=1; } else { borrow=0; } result.digits.push_back(diff); } result.removeLeadingZeros(); return result; } superint& operator-=(const superint& other) { *this=*this-other; return *this; } superint operator-() const { superint result=*this; if(result!=superint(0)) result.isNegative=!result.isNegative; return result; } superint operator*(const superint& other) const { superint result; result.digits.resize(digits.size()+other.digits.size(),0); result.isNegative=isNegative!=other.isNegative; for(long long i=0;i<digits.size();i++) { long long carry=0; for(long long j=0;j<other.digits.size()||carry;j++) { long long product=result.digits[i+j]+digits[i]*(j<other.digits.size()?other.digits[j]:0)+carry; result.digits[i+j]=product%10; carry=product/10; } } result.removeLeadingZeros(); return result; } superint& operator*=(const superint& other) { *this=*this*other; return *this; } superint operator/(const superint& other) const { if(other==superint(0)) throw runtime_error("Division by zero"); superint a=this->abs(); superint b=other.abs(); if(a<b) return superint(0); superint result; result.digits.clear(); result.isNegative=isNegative!=other.isNegative; superint current; current.digits.clear(); for(long long i=digits.size()-1;i>=0;i--) { current.digits.insert(current.digits.begin(),digits[i]); current.removeLeadingZeros(); long long quotientDigit=0; while(current>=b) { current=current-b; quotientDigit++; } result.digits.insert(result.digits.begin(),quotientDigit); } result.removeLeadingZeros(); return result; } superint& operator/=(const superint& other) { *this=*this/other; return *this; } superint operator%(const superint& other) const { if(other==superint(0)) throw runtime_error("Modulo by zero"); superint quotient=*this/other; return *this-quotient*other; } superint& operator%=(const superint& other) { *this=*this%other; return *this; } friend ostream& operator<<(ostream& os, const superint& num) { if(num.isNegative&&!(num.digits.size()==1&&num.digits[0]==0)) os<<'-'; for(long long i=num.digits.size()-1;i>=0;i--) os<<num.digits[i]; return os; } friend istream& operator>>(istream& is, superint& num) { string s; is>>s; num=superint(s); return is; } }; int main(){ superint a,b; cin>>a>>b; cout<<a+b; return 0; } -
Accepted Problems
-
Recent Activities
This person is lazy and didn't join any contests or homework.