这种题不要想复杂,直接找规律。找不出规律就打表找规律
#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 k,p; int main() { int i,j,kase=0; while(sf("%d%d",&k,&p)==2) { if(k/(p-1)%2==1) pf("YES\n"); else pf("NO\n"); } }
贪心
#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; struct node { int t,a; double f; }p[100005]; int cmp(const node& x,const node& y) { return x.f<y.f;} int main() { int i,j,kase=0; while(sf("%d",&n)==1) { for(i=0;i<n;i++) sf("%d",&p[i].t); for(i=0;i<n;i++) { sf("%d",&p[i].a); p[i].f = (double)p[i].t/p[i].a; } sort(p,p+n,cmp); long long sumt=0,res=0; for(i=0;i<n;i++) { sumt+=p[i].t; res+=p[i].a*sumt; } pf("%I64d\n",res); } }
原文:http://www.cnblogs.com/qlky/p/5296541.html