A.
读题读了好久。。。
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 const int INF=1<<28; 5 using namespace std; 6 int main() 7 { 8 int c,d; 9 int n,m,k; 10 while(cin>>c>>d) 11 { 12 cin>>n>>m>>k; 13 if (n*m <= k) 14 { 15 puts("0"); 16 continue; 17 } 18 int ex = (n*m-k)/n; 19 if ((n*m-k)%n!=0) 20 ex += 1; 21 int ey = n*m-k; 22 int ans = INF; 23 for (int i = 0;i <= ex; i++) 24 for (int j = 0;j <= ey; j++) 25 { 26 if (n*i+j >= n*m-k) 27 { 28 ans = min(ans,c*i+d*j); 29 } 30 } 31 cout<<ans<<endl; 32 } 33 return 0; 34 }
B.
开始排序+暴力。。写的好麻烦。。关键是题意不好弄懂。。理解了就好写了。。
1 #include <stdio.h> 2 #include <string.h> 3 const int N=100005; 4 int c[N]; 5 int main() 6 { 7 int n; 8 scanf("%d",&n); 9 int x,y,flag = 0; 10 memset(c,0,sizeof(c)); 11 for (int i = 0; i < n; i++) 12 { 13 scanf("%d%d",&x,&y); 14 if (c[y] < x) 15 { 16 flag = 1; 17 break; 18 } 19 else if (c[y]==x) 20 c[y]++; 21 } 22 if (!flag) 23 puts("YES"); 24 else 25 puts("NO"); 26 }
C.
直接暴力。。
1 #include <stdio.h> 2 #include <string.h> 3 const int N=1002; 4 int vis[N][N]; 5 int main() 6 { 7 int n,k; 8 while(~scanf("%d%d",&n,&k)) 9 { 10 int flag = 0; 11 int ans = 0; 12 memset(vis,0,sizeof(vis)); 13 for (int i = 1; i <= n; i++) 14 { 15 int cnt = 0; 16 for (int j = 1; j <= n; j++) 17 { 18 if (i==j||vis[i][j]) 19 continue; 20 if (cnt==k) 21 break; 22 vis[i][j] = 1; 23 vis[j][i] = 2; 24 cnt++,ans++; 25 } 26 if (cnt!=k) 27 { 28 flag = 1; 29 break; 30 } 31 } 32 if (flag) 33 { 34 puts("-1"); 35 continue; 36 } 37 printf("%d ",ans); 38 for (int i = 1; i <= n; i++) 39 { 40 for (int j = 1; j <= n; j++) 41 if (vis[i][j]==1) 42 { 43 printf("%d %d ",i,j); 44 } 45 } 46 } 47 return 0; 48 }