↓ Skip to main content
  1. Posts/

hdu 5835 || ccpc 2016 网络赛 1004 Danganronpa (模拟)

·561 words·2 mins
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

hdu 5835 题目链接 题意:n种礼物,每种a[i]个。现在有无穷个小朋友排成一排,分给每个人一个“普通”的礼物,一个“昂贵”的礼物(哪个普通哪个昂贵是自己定的,或者说,任意的) 要求是相邻的小朋友的普通的礼物不能是同一种。现在问最多能给多少小朋友分礼物。。。

思路:容易知道,因为昂贵的礼物是没有限制的。。所以没什么用。。考虑礼物总数sum..那么最多只可能分给sum/2个小朋友。。。然后再两个指针模拟一下。。记得特判n=1的情况。1A

代码实现
  1/* ***********************************************
  2Author :111qqz
  3Created Time :2016年08月14日 星期日 12时46分56秒
  4File Name :code/ccpc2016/1004.cpp
  5************************************************ */
  6#include <cstdio>
  7#include <cstring>
  8#include <iostream>
  9#include <algorithm>
 10#include <vector>
 11#include <queue>
 12#include <stack>
 13#include <set>
 14#include <map>
 15#include <string>
 16#include <cmath>
 17#include <cstdlib>
 18#include <deque>
 19#include <ctime>
 20#define fst first
 21#define sec second
 22#define lson l,m,rt<<1
 23#define rson m+1,r,rt<<1|1
 24#define ms(a,x) memset(a,x,sizeof(a))
 25typedef long long LL;
 26#define pi pair < int ,int >
 27#define MP make_pair
 28using namespace std;
 29const double eps = 1E-8;
 30const int dx4[4]={1,0,0,-1};
 31const int dy4[4]={0,-1,1,0};
 32const int inf = 0x3f3f3f3f;
 33const int N=11;
 34int n;
 35int a[N];
 36int total;
 37bool bian[N];
 38bool cmp(int a,int b)
 39{
 40    return a>b;
 41}
 42int main()
 43{
 44	#ifndef  ONLINE_JUDGE
 45	freopen("code/in.txt","r",stdin);
 46  #endif
 47	int T;
 48	cin>>T;
 49	int cas = 0 ;
 50	while (T--)
 51	{
 52	    printf("Case #%d: ",++cas);
 53	    scanf("%d",&n);
 54	    ms(bian,false);
 55	    total = 0 ;
 56	    for ( int i = 1 ; i <= n ; i++)
 57	    {
 58		scanf("%d",&a[i]);
 59		total +=a[i];
 60	    }
 61	    if (n==1)
 62	    {
 63		if (a[1]>1)
 64		puts("1");
 65		else puts("0");
 66		continue;
 67	    }
 68	    sort(a+1,a+n+1,cmp);
 69	    int R = total/2;
 70	    int cur = 0 ;
 71	    int i = 1;
 72	    int j = 2;
 73	    while (cur<R&&i<=n&&j<=n)
 74	    {
 75//		int x = a[i];
 76//		int y = a[j];
 77		if (a[i]==a[j])
 78		{
 79		    cur +=a[i]+a[j];
 80		    a[i] = 0;
 81		    a[j] = 0;
 82		    i = j+1;
 83		    j = i+1;
 84		}
 85		else  if (!bian[i])
 86		{
 87		    cur +=a[j]+a[j]+1;
 88		    a[i]-=(a[j]+1);
 89		    a[j] = 0;
 90		    j++;
 91		    if (a[i]<a[j]) swap(a[i],a[j]);
 92		    else bian[i] = true;
 93		}
 94		else
 95		{
 96		    cur +=a[j]+a[j];
 97		    a[i]-=a[j];
 98		    a[j] = 0;
 99		    j++;
100		    if (a[i]<a[j]) swap(a[i],a[j]);
101		}
102//		cout<<"cur:"<<cur<<endl;
103	    }
104	    cur = min(cur,R);
105	    printf("%d\n",cur);
106	}
107  #ifndef ONLINE_JUDGE
108  fclose(stdin);
109  #endif
110    return 0;
111}

Related

whust 2016 #1 D Zhenya moves from the dormitory (贪心,模拟)

·491 words·1 min
题目链接 傻逼模拟。。读完题就ac了。。。 代码实现 1/* *********************************************** 2Author :111qqz 3Created Time :2016年08月07日 星期日 18时04分18秒 4File Name :code/whust2016/#1/D.cpp 5************************************************ */ 6#include <cstdio> 7#include <cstring> 8#include <iostream> 9#include <algorithm> 10#include <vector> 11#include <queue> 12#include <stack> 13#include <set> 14#include <map> 15#include <string> 16#include <cmath> 17#include <cstdlib> 18#include <deque> 19#include <ctime> 20#define fst first 21#define sec second 22#define lson l,m,rt<<1 23#define rson m+1,r,rt<<1|1 24#define ms(a,x) memset(a,x,sizeof(a)) 25typedef long long LL; 26#define pi pair < int ,int > 27#define MP make_pair 28using namespace std; 29const double eps = 1E-8; 30const int dx4[4]={1,0,0,-1}; 31const int dy4[4]={0,-1,1,0}; 32const int inf = 0x3f3f3f3f; 33const int N=280; 34int n,m; 35int total,adva,advb; 36struct Friend 37{ 38 int money; 39 int adv; 40}f[N]; 41struct Room 42{ 43 int type; 44 int cost; 45 int adv; 46}r[N]; 47struct Ans 48{ 49 int val; 50 int rid; 51 int fid; 52 bool operator < (Ans b)const 53 { 54 return val>b.val; 55 } 56}ans[300*300]; 57int main() 58{ 59 #ifndef ONLINE_JUDGE 60 freopen("code/in.txt","r",stdin); 61 #endif 62 cin>>total>>adva>>advb; 63 cin>>n; 64 for ( int i = 1 ; i <= n ; i++) 65 scanf("%d %d",&f[i].money,&f[i].adv); 66 scanf("%d",&m); 67 for ( int i = 1 ; i <= m ; i++) 68 scanf("%d%d%d",&r[i].type,&r[i].cost,&r[i].adv); 69 int cnt = 0 ; 70 for ( int i = 1 ; i <= m ; i++) 71 { 72 if (r[i].type==1) 73 { 74 if (r[i].cost<=total) 75 { 76 cnt++; 77 ans[cnt].val = r[i].adv+adva; 78 ans[cnt].rid = i; 79 ans[cnt].fid = -1; 80 } 81 continue; 82 } 83 else 84 { 85 for ( int j = 0 ; j <= n ; j++) 86 { 87 if (j==0) //自己住双人间 88 { 89 if (r[i].cost<=total) 90 { 91 cnt++; 92 ans[cnt].val = r[i].adv+advb; 93 ans[cnt].rid = i ; 94 ans[cnt].fid = -1; 95 } 96 } 97 else 98 { 99 if (r[i].cost<=total*2&&r[i].cost<=f[j].money*2) 100 { 101 cnt++; 102 ans[cnt].val = r[i].adv+f[j].adv; 103 ans[cnt].rid = i ; 104 ans[cnt].fid = j; 105 } 106 } 107 } 108 } 109 } 110// for ( int i = 1 ; i <= cnt ; i++) 111// { 112// printf("val:%d room: %d friend : %d \n",ans[i].val,ans[i].rid,ans[i].fid); 113// } 114 if (cnt==0) 115 { 116 puts("Forget about apartments. Live in the dormitory."); 117 }else 118 { 119 sort(ans+1,ans+cnt+1); 120 if (r[ans[1].rid].type==1) 121 { 122 printf("You should rent the apartment #%d alone.\n",ans[1].rid); 123 } 124 else 125 { 126 if (ans[1].fid==-1) 127 { 128 printf("You should rent the apartment #%d alone.\n",ans[1].rid); 129 } 130 else 131 { 132 133 printf("You should rent the apartment #%d with the friend #%d.\n",ans[1].rid,ans[1].fid); 134 135 } 136 } 137 } 138 #ifndef ONLINE_JUDGE 139 fclose(stdin); 140 #endif 141 return 0; 142}

whust 2016 warm up E||codeforces 689 A. Mike and Cellphone (模拟)

·510 words·2 mins
cf689A 思路:一个老式的电话键盘。。。。给出一个拨号的移动路径。。。问这个路径是否唯一。 思路:如果唯一就说明。。。不能平移。。。否则不唯一。。 平移可以上下左右。。所以先写4个常亮数组。。。标记平移后的结果。。。设置不合法位就可以了。。。

BZOJ 1689: [Usaco2005 Open] Muddy roads 泥泞的路 (模拟)

·785 words·2 mins
1689: [Usaco2005 Open] Muddy roads 泥泞的路 # Time Limit: 5 Sec Memory Limit: 64 MB Submit: 311 Solved: 227 [Submit][Status][Discuss] Description # Farmer John has a problem: the dirt road from his farm to town has suffered in the recent rainstorms and now contains (1 <= N <= 10,000) mud pools. Farmer John has a collection of wooden planks of length L that he can use to bridge these mud pools. He can overlap planks and the ends do not need to be anchored on the ground. However, he must cover each pool completely. Given the mud pools, help FJ figure out the minimum number of planks he needs in order to completely cover all the mud pools.

bzoj1603: [Usaco2008 Oct]打谷机 (纱布题)

·589 words·2 mins
# Time Limit: 5 Sec Memory Limit: 64 MB Submit: 774 Solved: 593 [Submit][Status][Discuss] Description # Farmer John有一个过时的打谷机(收割小麦),它需要带子来带动。发动机驱动轮1总是顺时针旋转的,用来带动转轮2,转轮2来带动转轮3,等等。一共有n(2<=n<=1000)个转轮(n-1条带子)。上面的图解描述了转轮的两种连接方式,第一种方式使得两个轮子旋转的方向相同,第二种则相反。 给出一串带子的信息: *Si—驱动轮 *Di—被动轮 *Ci—连接的类型(0=直接连接,1=交叉连接) 不幸的是,列出的信息是随即的。 作为样例,考虑上面的图解,n=4,转轮1是驱动轮,可以得知最后转轮4是逆时针旋转的。

hdu 5611 || BC #69 div2 1002 Baby Ming and phone number

·757 words·2 mins
http://acm.hdu.edu.cn/showproblem.php?pid=5611 题意:给出n个电话号码(长度为11的字符串),满足特殊条件的价格为a,否则为b.特殊条件为最后5位数字一样,最后5位严格递增或者严格递减,最后8位是一个1980年1月一日到2016年12月31日的合法日期。问最后的价值。