SZU 7
A - Megacity
sqrtf是个坑
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("!\n") #define INF 10000 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf("\n") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue int n,s; struct point { int x,y,h; double d; }p[1005]; int cmp(const point& a,const point& b) { return a.d<=b.d;} int main() { int i,j; while(sf("%d%d",&n,&s)==2) { if(s == 1000000) { pf("%.7f\n",0); continue; } mem(p,0); for(i=0;i<n;i++) { sf("%d%d%d",&p[i].x,&p[i].y,&p[i].h); p[i].d = sqrtf(p[i].x*p[i].x + p[i].y*p[i].y); } sort(p,p+n,cmp); int sum = s; double res = 0; int ok = 0; for(i=0;i<n;i++) { sum+=p[i].h; if(sum>=1000000) { ok = 1; res = p[i].d; break; } } if(ok) { pf("%.7f\n",res); } else pf("-1\n"); } }
B - Let's Watch Football
一看就知道可以计算,不要想太复杂
int main() { int i,j; int a,b,c; while(sf("%d%d%d",&a,&b,&c)==3) { pf("%d\n",(a*c-b*c+b-1)/b); } }
C - Hopscotch
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define mp make_pair #define debug printf("!\n") #define INF 1<<30 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf("\n") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue int main() { int T,r,i,j,n; int a,x,y; while(sf("%d%d%d",&a,&x,&y)==3) { if(y%a==0) pf("-1\n"); else if(y<a) { if(2*x<a && 2*x>-a) pf("1\n"); else pf("-1\n"); } else { if((y-a)/a%2==0) { if(2*x<a && 2*x>-a) pf("%d\n",(y-a)/a/2*3+2); else pf("-1\n"); } else { if(x>0 && x<a) pf("%d\n",((y-a)/a+1)/2*3+1); else if(x<0 && x>-a) pf("%d\n",((y-a)/a+1)/2*3); else pf("-1\n"); } } } }
Working out
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("!\n") #define INF 10000 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf("\n") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue int n,m; int a[1005][1005]; int dp[1005][1005][4]; int main() { int i,j; while(sf("%d%d",&n,&m)==2) { for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { sf("%d",&a[i][j]); } } for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { dp[i][j][0] = max(dp[i-1][j][0],dp[i][j-1][0])+a[i][j]; } } for(i=n;i>=1;i--) { for(j=m;j>=1;j--) { dp[i][j][1] = max(dp[i+1][j][1],dp[i][j+1][1])+a[i][j]; } } for(i=1;i<=n;i++) { for(j=m;j>=1;j--) { dp[i][j][2] = max(dp[i-1][j][2],dp[i][j+1][2])+a[i][j]; } } for(i=n;i>=1;i--) { for(j=1;j<=m;j++) { dp[i][j][3] = max(dp[i+1][j][3],dp[i][j-1][3])+a[i][j]; } } int ans = 0; for(i=2;i<n;i++) { for(j=2;j<m;j++) { ans = max(ans,dp[i][j-1][0]+dp[i][j+1][1]+dp[i-1][j][2]+dp[i+1][j][3]); ans = max(ans,dp[i-1][j][0]+dp[i+1][j][1]+dp[i][j-1][3]+dp[i][j+1][2]); } } pf("%d\n",ans); } }
E - Anagram Search
打表法,因为?可以任意变,而且不在表范围内,所以只需要判断表范围内每个字母出现的数量
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define mp make_pair #define debug printf("!\n") #define INF 1<<30 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf("\n") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue char a[100005],b[100005]; int s[30],t[30]; int main() { int T,r,i,j,n; while(sf("%s%s",a,b)==2) { int al = strlen(a); int bl = strlen(b); mem(s,0); mem(t,0); for(i=0;i<bl;i++) { if(b[i]!='?') s[b[i]-'a']++; } int cnt = 0; for(i=0;i<al;i++) { if(a[i]!='?') t[a[i]-'a']++; int ok = 1; if(i>=bl-1) { for(j=0;j<26;j++) { if(t[j]>s[j]) { ok = 0; break; } } if(ok) cnt++; t[a[i-bl+1]-'a']--; } } pf("%d\n",cnt); } }