题目链接:http://acm.nefu.edu.cn/JudgeOnline/contest.php
题目大多是思维题,算法较少,不是很难。下面是解题报告,并附有标程
A#include <stdio.h> #include <string.h> #include <iostream> using namespace std; char a[10][10]; int main() { while(cin >> a[0]) { for(int i=1; i<8; i++) cin >>a[i]; int sum=0; int x,y; int count=0; for(int i=0; i<8; i++) for(int j=0; j<8; j++) if(a[i][j]=='B') count++; if(count==64) sum=8; else { for(int i=0; i<8; i++) { x=0; y=0; for(int j=0; j<8; j++) { if(a[i][j]=='B') x++; if(a[j][i]=='B') y++; } if(x==8) sum++; if(y==8) sum++; } } printf("%d\n",sum); } return 0; }
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> using namespace std; const int maxn=100005; typedef long long LL; const int mod=365*24*60*60; int n; struct note { LL x,y; bool operator < (const note &other)const { return x*other.y<other.x*y; } }a[maxn]; int main() { // freopen("data.in","r",stdin); // freopen("data.out","w",stdout); int T,tt=0; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%I64d%I64d",&a[i].x,&a[i].y); } sort(a,a+n); LL maxx=0; for(int i=0;i<n;i++) { maxx=(maxx+a[i].x+maxx*a[i].y)%mod; } printf("Case #%d: %I64d\n",++tt,maxx); } return 0; }
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; int n,a[1005],dp[1005],dp1[1005]; int main() { // freopen("data.in","r",stdin); //freopen("data.out","w",stdout); while(~scanf("%d",&n)) { for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n;i++) { dp[i]=1; for(int j=0;j<i;j++) { if(a[j]<a[i]) dp[i]=max(dp[i],dp[j]+1); } } /* for(int i=0;i<n;i++) { printf("%d ",dp[i]); } printf("\n");*/ for(int i=n-1;i>=0;i--) { dp1[i]=1; for(int j=n-1;j>i;j--) { if(a[j]<a[i]) { dp1[i]=max(dp1[i],dp1[j]+1); } } } /**for(int i=0;i<n;i++) { printf("%d ",dp1[i]); } printf("\n");*/ int maxx=-1; for(int i=0;i<n;i++) { // printf("%d ",dp[i]+dp1[i]-1); maxx=max(maxx,dp[i]+dp1[i]-1); } printf("%d\n",maxx); } return 0; }
#include <stdio.h> #include <string.h> #include <iostream> using namespace std; int a[10005]; int main() { int n,d; //freopen("data.in","r",stdin); // freopen("data.out","w",stdout); while(~scanf("%d%d",&n,&d)) { for(int i=0; i<n; i++) scanf("%d",&a[i]); int sum=0; for(int i=1; i<n; i++) { if(a[i]<=a[i-1]) { int x=a[i-1]-a[i]; a[i]+=(x/d)*d; sum+=x/d; if(a[i]<=a[i-1]) { a[i]+=d; sum++; } } } printf("%d\n",sum); } return 0; }
#include <stdio.h> #include <string.h> #include <iostream> #include <cmath> using namespace std; int getsum(int a,int t) { int ans=0; while(a) { ans+=a%t; a/=t; } return ans; } int gcd(int a,int b) { while(b) { int t=a%b; a=b; b=t; } return a; } int main() { int n; int ans=0; // freopen("data.in","r",stdin); // freopen("data.out","w",stdout); while(cin>>n) { ans=0; for(int i=2; i<=n-1; i++) ans+=getsum(n,i); int tb=n-2; int tt=gcd(ans,tb); cout<<ans/tt<<'/'<<tb/tt<<endl; } return 0; }G
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; long long n,m; int main() { // freopen("data.in","r",stdin); // freopen("data.out","w",stdout); while(~scanf("%lld%lld",&n,&m)) { if(n%2==0) { printf("%lld\n",((m+1)/2+m/2)*(n/2)); } else { printf("%lld\n",((m+1)/2+m/2)*(n/2)+(m+1)/2); } } return 0; }H
棋盘最后只可能刷成两种情况1、棋盘的横纵坐标满足(i+j)%2==1的全刷成白色,其余刷成黑色 2、棋盘的横纵坐标满足(i+j)%2==0的全刷成白色,其余刷成黑色 。两种情况,取最小的改变值就可以了
#include <iostream> using namespace std; const int N = 110; char s[N][N]; int main(){ int n,m; while(cin >> n >> m){ for(int i = 0;i < n;i++){ cin >> s[i]; } int white = 0,black = 0; for(int i = 0,flag = 0;i < n;i++,flag ^= 1){ for(int j = 0,f = flag;j < m;j++,f ^= 1){ white += ((s[i][j] - '0') != f); black += ((s[i][j] - '0') == f); } } cout << min(white,black) << endl; } return 0; }