本文主要是介绍2013长春现场赛,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
2013长春现场赛水题 虽然我想不出思路看别人题解懂的
#include<stdio.h>
#include<string.h>
#include<vector>
#include<stack>
using namespace std;
const int maxn = 105;
const int inf = 1<<30;
int n,m,pos;
__int64 s[maxn],p[maxn],price[maxn];int find( __int64 q )
{int ld = 1,rd = n,mid;int ans = ld;while( ld <= rd ){mid = (ld+rd)/2;if( s[mid] <= q ){ans = mid;ld = mid + 1;}elserd = mid - 1;}return ans;
}int main()
{//freopen( "data.txt","r",stdin ); int t;__int64 q;scanf("%d",&t);while( t-- ){scanf("%d%d",&n,&m);for( int i = 1; i <= n; i ++ ){scanf("%I64d%I64d",&s[i],&p[i]);}price[n] = s[n] * p[n];for( int i = n; i >= 1; i -- ){price[i-1] = price[i];if( price[i] > s[i] * p[i] ) price[i] = s[i] * p[i];}for( int i = 1; i <= m; i ++ ){scanf("%I64d",&q);int ss = find(q);if( ss == n ) printf("%I64d\n",p[ss] * q);elseprintf("%I64d\n",min( p[ss]*q,price[ss+1] ));}}return 0;
}
这篇关于2013长春现场赛的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!