CF #264 div2
2014-08-30 20:56:12
A题,不说什么了- =,只能买一颗糖的设定太违和了,唯一的小trick:某颗糖为a dollas,0 cent的话找0个糖而不是100。
1 /************************************************************************* 2 > File Name: a.cpp 3 > Author: Nature 4 > Mail: 564374850@qq.com 5 > Created Time: Sat 30 Aug 2014 03:29:07 PM CST 6 ************************************************************************/ 7 8 #include <cstdio> 9 #include <cstring> 10 #include <cstdlib> 11 #include <cmath> 12 #include <iostream> 13 #include <algorithm> 14 using namespace std; 15 16 int n,s; 17 int tmax = -1; 18 int x,y; 19 20 int main(){ 21 scanf("%d%d",&n,&s); 22 for(int i = 0; i < n; ++i){ 23 scanf("%d%d",&x,&y); 24 if(s > x && y != 0){ 25 tmax = max(tmax,100 - y); 26 } 27 if(s >= x && y == 0) tmax = max(tmax,0); 28 } 29 printf("%d\n",tmax); 30 return 0; 31 }
B题,有点逗比的题目,仔细想想就知道是求所有数中的最大值。
1 /************************************************************************* 2 > File Name: b.cpp 3 > Author: Nature 4 > Mail: 564374850@qq.com 5 > Created Time: Sat 30 Aug 2014 03:50:07 PM CST 6 ************************************************************************/ 7 8 #include <cstdio> 9 #include <cstring> 10 #include <cstdlib> 11 #include <cmath> 12 #include <iostream> 13 #include <algorithm> 14 using namespace std; 15 16 int n,h,tmax; 17 18 int main(){ 19 scanf("%d",&n); 20 tmax = -1; 21 for(int i = 1; i <= n; ++i){ 22 scanf("%d",&h); 23 tmax = h > tmax ? h : tmax; 24 } 25 printf("%d\n",tmax); 26 return 0; 27 }
C题,挺巧妙的题目,仔细考虑就会发现两个放主教的位置要达到这样的要求:横、纵坐标之和的奇偶性不同。用i +j-1来编负对角线,用n-i+j来边正对角线。
1 /************************************************************************* 2 > File Name: c.cpp 3 > Author: Nature 4 > Mail: 564374850@qq.com 5 > Created Time: Sat 30 Aug 2014 03:56:10 PM CST 6 ************************************************************************/ 7 8 #include <cstdio> 9 #include <cstring> 10 #include <cstdlib> 11 #include <cmath> 12 #include <iostream> 13 #include <algorithm> 14 using namespace std; 15 typedef long long ll; 16 17 ll n; 18 ll g[2005][2005]; 19 ll sum1[5005]; 20 ll sum2[5005]; 21 ll oddmax; 22 ll evenmax; 23 24 int main(){ 25 ll i1,j1,i2,j2; 26 oddmax = evenmax = -1; 27 scanf("%I64d",&n); 28 for(ll i = 1; i <= n; ++i){ 29 for(ll j = 1; j <= n; ++j){ 30 scanf("%I64d",&g[i][j]); 31 sum1[i + j - 1] += g[i][j]; 32 sum2[n - i + j] += g[i][j]; 33 } 34 } 35 for(ll i = 1; i <= n; ++i){ 36 for(ll j = 1; j <= n; ++j){ 37 ll v = sum1[i + j - 1] + sum2[n - i + j] - g[i][j]; 38 if((i + j) % 2){ 39 if(v > oddmax){ 40 oddmax = v; 41 i1 = i; 42 j1 = j; 43 } 44 } 45 else{ 46 if(v > evenmax){ 47 evenmax = v; 48 i2 = i; 49 j2 = j; 50 } 51 } 52 } 53 } 54 printf("%I64d\n",oddmax + evenmax); 55 printf("%I64d %I64d %I64d %I64d\n",i1,j1,i2,j2); 56 return 0; 57 }
D题,这题的话。。在结束前10分钟想出来了QAQ,但是时间不够了,呵呵。思路就是用dp[i][j]来表示,i表示数1~n,j表示第几列,举个例子dp[1][1...5]就表示数1在第1,2,3,4,5行中的位置。以第一行为基准,对于第i个数 ,当且仅当:dp[v[i]][k] > dp[v[j]][k] (v[]表示第一行的数,i > j , 1 <= k <= 5)满足时,才能构成上升关系,这样就把LCS的问题转化成了LIS,具体见程序。
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <iostream> 5 using namespace std; 6 7 int dp[1005][6]; 8 int cnt[1005]; 9 int n,k,v[6][1005];; 10 11 int main(){ 12 scanf("%d%d",&n,&k); 13 for(int i = 1; i <= k; ++i){ 14 for(int j = 1; j <= n; ++j){ 15 scanf("%d",&v[i][j]); 16 dp[v[i][j]][i] = j; 17 } 18 } 19 int tmax = 0,flag,a,b; 20 for(int i = 1; i <= n; ++i){ 21 a = v[1][i]; 22 cnt[a] = 1; 23 for(int j = 1; j < i; ++j){ 24 b = v[1][j]; 25 flag = 1; 26 if(cnt[b] + 1 <= cnt[a]) continue; 27 for(int p = 2; p <= k; ++p) if(dp[a][p] < dp[b][p]) flag = 0; 28 if(flag) cnt[a] = cnt[b] + 1; 29 } 30 tmax = cnt[a] > tmax ? cnt[a] : tmax; 31 } 32 printf("%d\n",tmax); 33 return 0; 34 }