Sanxin universal set of simulated game

Tao Tao grab Apple:

topic:

Went to the harvest season, the trees end up with a lot of Tao Tao, wrong, a lot of apples, there are many small Tao Tao came to pick apples. Each Tao Tao wants the greatest apple, so had an argument, in order to solve their conflicts, the question of man - a special rule, according to the size of the weight given order, each round is the first by fat first pick (to take care of fat), each of Tao Tao is very smart, do not miss the largest apple eyes. Now the question is, a total of apples n, m a Tao Tao, you want to order the original Tao Tao can grab the output of Apple's total size of each.

 

Ideas: flood problem! ! ! Direct simulation.

code:

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 typedef long long ll;
 5 
 6 int n,m;
 7 int app[100001];
 8 ll sum[100001];
 9 struct ozj {
10     int wei,num;
11 } tt[100001];
12 
13 bool cmd(int x,int y) {
14     return x>y;
15 }
16 bool cmp(ozj x,ozj y) {
17     return x.wei>y.wei;
18 }
19 int main() {
20     scanf("%d%d",&n,&m);
21     for(int i=1; i<=n; ++i) {
22         scanf("%d",&app[i]);
23     }
24     for(int i=1; i<=m; ++i) {
25         scanf("%d",&tt[i].wei);
26         tt[i].num=i;
27     }
28     sort(tt+1,tt+m+1,cmp);
29     sort(app+1,app+1+n,cmd);
30     int j=1;
31     for(int i=1; i<=n; ++i) {
32         if(j>m) {
33             j=1;
34         }
35         sum[tt[j].num]+=app[i];
36         j++;
37     }
38     for(int i=1; i<=m; ++i) {
39         printf("%lld ",sum[i]);
40     }
41     return 0;
42 }

 

Opening dance:

topic:

In looking forward to people around the world, the 2008 Beijing Olympic Games finally held a grand!

To demonstrate the fine traditional culture of the Chinese nation profound, who is responsible for orchestrating the opening ceremony of the opening dance meticulous, and strive to perfect every detail. On the team problem is the use of "Tianyuan" array or "place" array, we discuss seven days and nights, still no results. So, they want to help the computer to calculate the cost of two kinds of formation.

The teams are arranged in a two-dimensional plane, and to be (0,0) such that the center point of symmetry on keeping the United States. "Day round" is a circular array, and "place" is a front side parallel to the axis of the square. Due to some factors, the formation claims cover some point (the edge can).

Your task is to calculate the formation of two kinds of minimum area capable of covering these points.

 

Ideas:

Water problem, do not want to talk about.

code:

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cmath>
 4 using namespace std;
 5 
 6 int n,x,y;
 7 double pi=3.14;
 8 long long max1=-1,max2=-1;
 9 double ans1=-1;
10 long long ans2=-1;
11 double len;
12 
13 int max(int x,int y) {
14     if(x>y) {
15         return x;
16     }
17     return y;
18 }
19 double maxn(double x,double y) {
20     if(x>y) {
21         return x;
22     }
23     return y;
24 }
25 bool cmp(int x,int y) {
26     return x>y;
27 }
28 int main() {
29     scanf("%d",&n);
30     for(int i=1; i<=n; i++) {
31         scanf("%d%d",&x,&y);
32         len=sqrt(abs(x)*abs(x)+abs(y)*abs(y));
33         max1=max(max1,x);
34         max2=max(max2,y);
35         ans1=maxn(ans1,len);
36     }
37     ans2=max(max1,max2);
38     ans1=ans1*ans1*pi;
39     ans2=2*ans2*2*ans2;
40     printf("%.0lf\n%lld",ans1,ans2);
41     return 0;
42 }

 

Set up telephone line:

topic:

 Farmer John going to the telephone line to lead his farm, but his telecommunications company does not intend to provide free services. So, FJ need to pay a fee to the telecommunications company.

FJ farm around the distribution N (1 <= N <= 1,000) root by 1..N numbered sequentially discarded telephone poles, telephone poles between any two telephone lines are not connected. Total P (1 <= P <= 10,000) can be pulled on between the telephone line of a telephone pole, those due to the remaining separated too far and can not be connected.

I-two endpoints of a telephone pole are A_i, B_i, the distance between them is L_i (1 <= L_i <= 1,000,000). To ensure that the data appear at most each pair {A_i, B_i} 1 times. Telephone poles numbered 1 has access to a national telephone network, a telephone line are all whole farm is connected to the N number on telephone poles. In other words, FJ's task is to find a path only the No. 1 and No. N telephone poles connected together and the rest of the telephone poles is not necessarily connected to the telephone network.

After negotiations, the telecommunications company finally agreed to free FJ link K (0 <= K <N) specified by FJ telephone pole pairs. In addition to those for the telephone line, the cost of pay FJ need thereof, wherein the length equal to the longest of the telephone line (telephone line connecting each of a single pair of telephone poles). If the total expenditure of telephone poles that require no more than K pair, FJ is zero.

Please you do the math, FJ least how much money to spend on the telephone line.

 

Ideas:

Binary answer, when determining whether feasible only needs to determine whether to find a path that is larger than our value bipartite sides on the path does not exceed k item, essentially the shortest do a modification of it, less than two minutes the boundary value can be seen as the right side is 0 , is larger than the right side can be seen as a direct short circuit for the most see is less than k can.

Space and time can not optimize (best optimize it);

The following code is optimized.

code:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<queue>
 5 #define N 2100
 6 #define M 2100000
 7 using namespace std;
 8 int n,p,k;
 9 int st[N+1],tot;
10 struct edge
11 {
12     int to,val,last;
13 }e[M<<1|1];
14 void add(int a,int b,int c)
15 {
16     e[++tot].to=b;
17     e[tot].val=c;
18     e[tot].last=st[a];
19     st[a]=tot;
20 }
21 struct node
22 {
23     int x,y;
24 };
25 int dis[N+1][N+1];
26 bool vis[N+1][N+1];
27 int spfa()
28 {
29     queue<node> q;
30     q.push((node){1,0});
31     memset(dis,0x3f,sizeof(dis));
32     dis[1][0]=0;
33     while(!q.empty())
34     {
35         node u=q.front();
36         vis[u.x][u.y]=false;
37         q.pop();
38         for(int i=st[u.x];i!=0;i=e[i].last)
39         {
40             int v=e[i].to;
41             if(max(dis[u.x][u.y],e[i].val)<dis[v][u.y])
42             {
43                 dis[v][u.y]=max(dis[u.x][u.y],e[i].val);
44                 if(!vis[v][u.y])
45                     vis[v][u.y]=true,q.push((node){v,u.y});
46             }
47             if(u.y<k&&dis[u.x][u.y]<dis[v][u.y+1])
48             {
49                 dis[v][u.y+1]=dis[u.x][u.y];
50                 if(!vis[v][u.y+1])
51                     vis[v][u.y+1]=true,q.push((node){v,u.y+1});
52             }
53         }
54     }
55     int res=2147483647;
56     for(int i=0;i<=k;i++)
57         res=min(res,dis[n][i]);
58     return res;
59 }
60 int main()
61 {
62     scanf("%d %d %d",&n,&p,&k);
63     for(int i=1;i<=p;i++)
64     {
65         int a,b,c;
66         scanf("%d %d %d",&a,&b,&c);
67         add(a,b,c),add(b,a,c);
68     }
69     int ans=spfa();
70     if(ans>11000000)
71         printf("-1");
72     else
73         printf("%d",years);
74      return  0 ;
75 }

 

Fruit shop:

topic:

In a market, for there are a lot of open space and residential. Now, the city opened a new fruit shop, in order to say hello to urban residents, fruit shop decided to send two courier to send a box of fruit to every house. Due to the large weight of a box of fruit, so you can only deliveryman carrying a box of fruit.

You can think of this city as a chessboard N rows M columns, each grid is either open space or residential, or a fruit shop. If the grid is a space, then use 0..9 to represent the height of the space; if it is residential, then use $ to represent, if a fruit shop, then use X to represent. Into another from a lattice grid, lattice if and only if two adjacent, i.e. share an edge.

If two cells in a residential or fruit shop, it takes two minutes.

If the grid are two open space, then press the height of discussion. If the height of the two open space of the same, the time it takes 1 minute; 1 if the difference in height between the two, it takes three minutes; if both the height is more than 1, then each can not enter.

Now, the fruit shop owner wanted to know if the whole city of residence have received their fruits, how much time do the minimum required? If you never sent, please output -1.

 

Ideas:

First to build a trellis, run again spfa (data is very small), pretreatment fruit shop to the time required for residential, multiplied by 2, violent seizure best answer, minus two in the longest time can be.

Pay attention to details! !

code:

  1 #include<iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<queue>
  5 #define N 210
  6 using namespace std;
  7 const int dx[4]={1,-1,0,0};
  8 const int dy[4]={0,0,1,-1};
  9 int abs(int x){if(x<0)return -x;return x;}
 10 char map[N+1][N+1];
 11 int sx,sy;
 12 int tx[N+1],ty[N+1],cnt;
 13 int st[N+1][N+1],tot;
 14 struct edge
 15 {
 16     int x,y,last,val;
 17 }e[N*N<<1|1];
 18 void add(int x,int y,int a,int b,int c)
 19 {
 20     e[++tot].x=a,e[tot].y=b;
 21     e[tot].val=c;
 22     e[tot].last=st[x][y];
 23     st[x][y]=tot;
 24 }
 25 int dis[N+1][N+1];
 26 bool vis[N+1][N+1];
 27 struct node
 28 {
 29     int x,y;
 30 };
 31 void spfa()
 32 {
 33     queue<node> q;
 34     q.push((node){sx,sy});
 35     memset(dis,0x3f,sizeof(dis));
 36     dis[sx][sy]=0;
 37     while(!q.empty())
 38     {
 39         node u=q.front();
 40         vis[u.x][u.y]=false;
 41         q.pop();
 42         for(int i=st[u.x][u.y];i!=0;i=e[i].last)
 43         {
 44             node v=(node){e[i].x,e[i].y};
 45             if(dis[u.x][u.y]+e[i].val<dis[v.x][v.y])
 46             {
 47                 dis[v.x][v.y]=dis[u.x][u.y]+e[i].val;
 48                 if(!vis[v.x][v.y])
 49                     vis[v.x][v.y]=true,q.push((node){v.x,v.y});
 50             }
 51         }
 52     }
 53 }
 54 bool flag[N+1];
 55 int ans=2147483647;
 56 void dfs(int h)
 57 {
 58     int sum1=0,sum2=0,max1=0,max2=0;
 59     for(int i=1;i<=cnt;i++)
 60     {
 61         if(flag[i])
 62             sum1+=dis[tx[i]][ty[i]]<<1,max1=max(max1,dis[tx[i]][ty[i]]);
 63         else
 64             sum2+=dis[tx[i]][ty[i]]<<1,max2=max(max2,dis[tx[i]][ty[i]]);
 65     }
 66     if(sum1==0)
 67         ans=min(ans,sum2-max2);
 68     if(sum2==0)
 69         ans=min(ans,sum1-max1);
 70     if(sum1!=0&&sum2!=0)
 71         ans=min(ans,max(sum1-max1,sum2-max2));
 72     if(h>=cnt+1)
 73         return; 
 74     flag[h]=true;
 75     dfs(h+1);
 76     flag[h]=false;
 77     dfs(h+1);
 78 }
 79 int main()
 80 {
 81 //    freopen("水果店.in","r",stdin);
 82     int n,m;
 83     scanf("%d %d",&n,&m);
 84     for(int i=1;i<=n;i++)
 85         scanf("%s",map[i]+1);
 86     for(int i=1;i<=n;i++)
 87         for(int j=1;j<=m;j++)
 88         {
 89             if(map[i][j]=='$')
 90                 tx[++cnt]=i,ty[cnt]=j;
 91             if(map[i][j]=='X')
 92                 sx=i,sy=j;
 93             for(int k=0;k<4;k++)
 94             {
 95                 int dex=i+dx[k],dey=j+dy[k];
 96                 if(dex<=0||dex>n||dey<=0||dey>m)
 97                     continue;
 98                 if(map[dex][dey]=='X'||map[dex][dey]=='$')
 99                     add(i,j,dex,dey,2),add(dex,dey,i,j,2);
100                 else
101                     if(abs((int)(map[dex][dey]-map[i][j]))==1)
102                         add(i,j,dex,dey,3);
103                     else
104                         if(map[dex][dey]==map[i][j])
105                             add(i,j,dex,dey,1);
106             }
107         }
108     spfa();
109     if(cnt==0)
110     {
111         printf("0");
112         return 0;
113     }
114     for(int i=1;i<=cnt;i++)
115         if(dis[tx[i]][ty[i]]>10000000)
116         {
117             printf("-1");
118             return 0;
119         }
120 //    for(int i=1;i<=cnt;i++)
121 //        printf("%d %d %d %d %d\n",sx,sy,tx[i],ty[i],dis[tx[i]][ty[i]]);
122     dfs(1);
123     printf("%d",ans);
124     return 0;
125 }

 

to sum up:

Today's topic is water, it is water, it is water. But I only took 226 minutes, hey ╮ (╯ ▽ ╰) ╭.

We will continue to refuel.

Guess you like

Origin www.cnblogs.com/ouzijun-OJ/p/11519006.html