A.New Year and Hurry
手速题
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);
int n,k;
cin>>n>>k;
int t=240-k;
int c=0;
For(i,n) {
if (t>=i*5) t-=i*5,c++;
}
cout<<c<<endl;
return 0;
}
B.New Year and North Pole
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int main()
{
// freopen("B.in","r",stdin);
// freopen(".out","w",stdout);
int n;
cin>>n;
bool fl=1;
int s=0,l=20000;
For(i,n) {
int p=read();
string st;
cin>>st;
if (s==0&&st[0]!='S') {
fl=0; break;
}
if (s==l&&st[0]!='N') {
fl=0; break;
}
if (st[0]=='S') s+=p;
if (st[0]=='N') s-=p;
if (s<0||s>l) {
fl=0; break;
}
}
if (s!=0) fl=0;
if (fl) puts("YES") ;else puts("NO");
return 0;
}
C.New Year and Rating
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
vector<pi > v;
int main()
{
// freopen("C.in","r",stdin);
// freopen(".out","w",stdout);
int n=read();
int now=0;
For(i,n) {
int a=read(),b=read();
v.pb(mp(now,b));
now+=a;
}
sort(ALL(v));
bool fl=1;
Rep(i,n-1)
if (v[i].se<v[i+1].se)
fl=0;
if (!fl) puts("Impossible");
else {
if (v[0].se==1) puts("Infinity");
else {
int p=0;
Rep(i,n) if (v[i].se==2) {
p=v[i].fi;
}
++p;
p=1900-p+now;
cout<<p<<endl;
}
}
return 0;
}
D.New Year and Fireworks
数组开小了居然不RE……没地方(┬_┬)
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int n,t[31];
int dir[8][2]={{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1}};
bool f[340][340][9][31][5]={0};
bool b[500][500]={0};
int ans=0;
void dfs(int x,int y,int d,int nowi,int l) {
if (f[x][y][d][nowi-1][l]) return;
f[x][y][d][nowi-1][l]=1;
ans+=b[x][y]==0;
b[x][y]=1;
if (nowi==n && l==t[n]) {
return;
}
if (l==t[nowi]) {
nowi++,l=0;
int d2=(d+1)%8;
int nx=x+dir[d2][0],ny=y+dir[d2][1];
dfs(nx,ny,d2,nowi,l);
d2=(d+7)%8;
nx=x+dir[d2][0],ny=y+dir[d2][1];
dfs(nx,ny,d2,nowi,l);
return;
}
++l;
int d2=d,nx=x+dir[d2][0],ny=y+dir[d2][1];
dfs(nx,ny,d2,nowi,l);
}
bool q[1000][1000][8],q2[1000][1000][8];
void bfs() {
MEM(q) MEM(q2)
q[155][155][0]=1;
b[155][155]=1;ans++;
int nowi=1,l=0;
while(nowi!=n||l!=t[nowi]) {
if (l==t[nowi]) {
Rep(i,320) Rep(j,320) Rep(k,8) if (q[i][j][k]) {
int d2=(k+1)%8;
int nx=i+dir[d2][0],ny=j+dir[d2][1];
q2[nx][ny][d2]=1;
d2=(k+7)%8;
nx=i+dir[d2][0],ny=j+dir[d2][1];
q2[nx][ny][d2]=1;
}
nowi++,l=0;
}
else {
Rep(i,320) Rep(j,320) Rep(k,8) if (q[i][j][k]) {
int d2=k,nx=i+dir[d2][0],ny=j+dir[d2][1];
q2[nx][ny][d2]=1;
}
l++;
}
Rep(i,320) Rep(j,320) Rep(k,8) {
q[i][j][k]=q2[i][j][k],q2[i][j][k]=0;
if (q[i][j][k]) {
ans+=b[i][j]==0;
b[i][j]=1;
}
}
}
}
int main()
{
// freopen("D.in","r",stdin);
// freopen("D.out","w",stdout);
cin>>n;
For(i,n) cin>>t[i],t[i]--;
bfs();
// dfs(155,155,0,1,0);
cout<<ans<<endl;
return 0;
}