标签:c51 tps while abc bool 暴力 个数 memset 最小
连打了三天的比赛,有点困。
#include #define ll long long #define F first #define S second #define P pair #define FOR(i,a,b) for(int i=a;i<=b;i++) #define V vector #define RE return #define ALL(a) a.begin(),a.end() #define MP make_pair #define PB push_back #define PF push_front #define FILL(a,b) memset(a,b,sizeof(a)) using namespace std; int f[100005],t[100005]; int main() { ios::sync_with_stdio(0); cin.tie(0); int ans=0; int n,m; cin>>n>>m; string s; int x,sum=0; FOR(i,1,m) { cin>>x>>s; if(f[x])continue; if(s=="AC") { ans+=t[x]; sum++; f[x]=1; } else { t[x]++; } } cout<<sum<<‘ ‘<<ans; return 0; }
#include #define ll long long #define F first #define S second #define P pair #define FOR(i,a,b) for(int i=a;i<=b;i++) #define V vector #define RE return #define ALL(a) a.begin(),a.end() #define MP make_pair #define PB push_back #define PF push_front #define FILL(a,b) memset(a,b,sizeof(a)) using namespace std; int n,m; bool f[25][25],vis[25][25]; struct node { int h,l; int step; }; queue q; int fx[4][2]= { 0,1, 0,-1, 1,0, -1,0 }; int bfs(int x,int y,int zx,int zy) { while(!q.empty())q.pop(); node cur,t; cur.h=x; cur.l=y; cur.step=0; q.push(cur); memset(vis,0,sizeof(vis)); while(!q.empty()) { cur=q.front(); q.pop(); x=cur.h; y=cur.l; if(x<1||x>n||y<1||y>m)continue; if(f[x][y])continue; if(vis[x][y])continue; vis[x][y]=1; if(zx==x&&zy==y) { return cur.step; } FOR(i,0,3) { t.h=x+fx[i][0]; t.l=y+fx[i][1]; t.step=cur.step+1; q.push(t); } } return -2147483647; } int main() { ios::sync_with_stdio(0); cin.tie(0); char c; cin>>n>>m; for(int i=1; i<=n; i++) { FOR(j,1,m) { cin>>c; if(c==‘#‘)f[i][j]=1; } } int maxi=0; FOR(i,1,n) { FOR(j,1,m) { FOR(i1,1,n) { FOR(j1,1,m) { maxi=max(maxi,bfs(i,j,i1,j1)); } } } } cout<<maxi; return 0; }
#include #define int long long #define F first #define S second #define P pair #define FOR(i,a,b) for(int i=a;i<=b;i++) #define V vector #define RE return #define ALL(a) a.begin(),a.end() #define MP make_pair #define PB push_back #define PF push_front #define FILL(a,b) memset(a,b,sizeof(a)) using namespace std; int inv[100005],finv[100005],f[100005]; int n,a[100005],mod=1000000007; void C() { f[0]=1; finv[0]=1; finv[1]=1; f[1]=1; inv[1]=1; FOR(i,2,n) { f[i]=f[i-1]*i%mod; inv[i]=mod-inv[mod%i]*(mod/i)%mod; finv[i]=finv[i-1]*inv[i]%mod; } } int c(int n,int k) { if(n return f[n]*(finv[k]*finv[n-k]%mod)%mod; } signed main() { ios::sync_with_stdio(0); cin.tie(0); int k; cin>>n>>k; FOR(i,1,n)cin>>a[i]; sort(a+1,a+n+1); C(); int ans=0; FOR(i,1,n) { ans+=c(i-1,k-1)*a[i]%mod; ans=(ans+mod)%mod; ans-=c(n-i,k-1)*a[i]%mod; ans=(ans+mod)%mod; } cout<<ans; return 0; }
AtCoder Beginner Contest151参赛感悟
标签:c51 tps while abc bool 暴力 个数 memset 最小
原文地址:https://www.cnblogs.com/njwsf/p/12189352.html