精华内容
下载资源
问答
  • Collapse OS in Forth

    2021-01-10 19:09:16
    <p>Forth is one of my past loves. It can be used for most things rather well and is the precursor to PostScript found in printers. Using Forth one could conceivably construct a Display PostScript like...
  • Back and Forth 题解

    2019-03-15 22:11:47
    题面: Farmer John has two milking barns, each of which has a large milk tank as well as a storage closet containing 10 buckets of various... He likes to carry milk back and forth between the two ba...

    题面:

    在这里插入图片描述

    翻译:

    FJ打算锻炼♂身体,方法是每天拿着水桶搬牛奶.
    已知a, b两个桶中都有1000加仑的奶. a, b两个桶附近各有10个小桶.
    星期二,他从a那边随机拿一个桶,并且装满奶(从a桶中倒出来的奶),然后把这桶奶抬到b那边,倒到b桶里.临走前他把今天用的桶留在b桶附近.
    星期三,他从b那边随机拿一个桶(包括之前留在b那边的),装满奶(从b桶中倒出来的奶),然后把这桶奶抬到a那边,倒到a桶里.临走前他把今天用的桶留在a桶附近.
    星期四 他从a那边随机拿一个桶(包括之前留在a那边的),并且装满奶(从a桶中倒出来的奶),然后把这桶奶抬到b那边,倒到b桶里.临走前他把今天用的桶留在b桶附近.
    星期五,他从b那边随机拿一个桶(包括之前留在b那边的),装满奶(从b桶中倒出来的奶),然后把这桶奶抬到a那边,倒到a桶里.临走前他把今天用的桶留在a桶附近.
    这样之后,他最终可能在a桶看到多少种情况?

    输入:

    第一行10个数字,分别代表在a那边的10个桶的容量
    第二杆10个数字,分别代表在b那边的10个桶的容量

    题目分析:

    他每天拿来拿去的桶有以下几种可能:

    • 每天都是同一个桶,那么他最后能看到的情况和原本相同.
    • 去b的两天和去a的两天里面都各有一天是拿了同一个桶
    • 每天都拿着不同的桶.
      把以上的四种情况都枚举一次,并且用一个数组来记录每种情况是否曾经出现过(防止重复计算).

    代码:

    #include<stdio.h>
    
    int ans;
    int a[10], b[10];
    bool possible[3000];
    
    int main(){
        for(int i = 0; i < 10; ++i) scanf("%d", a+i);
        for(int i = 0; i < 10; ++i) scanf("%d", b+i);
        possible[1000] = 1;ans++;
    
        for(int i = 0; i < 10; ++i){
            for(int j = 0; j < 10; ++j){
                if(!possible[1000 - a[i] + b[j]]){
                    possible[1000 - a[i] + b[j]] = 1;
                    ans++;
                }
            }
        }
        for(int i = 0; i < 10; ++i){
            for(int j = 0; j < 10; ++j){
                for(int k = 0; k < 10; ++k){
                    for(int l = 0; l < 10; ++l){
                        if(!possible[1000 - a[i] + b[j] - a[k] + b[l]] && i != k && j != l){
                            possible[1000 - a[i] + b[j] - a[k] + b[l]] = 1;
                            ans++;
                        }
                    }
                }
            }
        }
        printf("%d\n", ans);
    }
    
    
    展开全文
  • codeforces Back and Forth

    2019-03-10 13:58:34
    dfs 模拟题面题意分析代码 题面 Farmer John has two milking barns, each of which has a large milk tank as well as a storage closet containing 10 buckets of... He likes to carry milk back and forth betwe...

    题面

    Farmer John has two milking barns, each of which has a large milk tank as well as a storage closet containing 10 buckets of various sizes. He likes to carry milk back and forth between the two barns as a means of exercise. On Monday, Farmer John measures exactly 1000 gallons of milk in the tank of the first barn, and exactly 1000 gallons of milk in the tank of the second barn.

    On Tuesday, he takes a bucket from the first barn, fills it, and carries the milk to the second barn, where he pours it into the storage tank. He leaves the bucket at the second barn.

    On Wednesday, he takes a bucket from the second barn (possibly the one he left on Tuesday), fills it, and carries the milk to the first barn, where he pours it into the storage tank. He leaves the bucket at the first barn.

    On Thursday, he takes a bucket from the first barn (possibly the one he left on Wednesday), fills it, and carries the milk to the second barn, where he pours it into the tank. He leaves the bucket at the second barn.

    On Friday, he takes a bucket from the second barn (possibly the one he left on Tuesday or Thursday), fills it, and carries the milk to the first barn, where he pours it into the tank. He leaves the bucket at the first barn.

    Farmer John then measures the milk in the tank of the first barn. How many possible different readings could he see?

    Input
    The first line of input contains 10 integers, giving the sizes of the buckets initially at the first barn. The second line of input contains 10 more integers, giving the sizes of the buckets initially at the second barn. All bucket sizes are in the range 1…100.

    Output
    Please print the number of possible readings Farmer John could get from measuring the milk in the tank of the first barn after Friday.

    input
    1 1 1 1 1 1 1 1 1 2
    5 5 5 5 5 5 5 5 5 5
    output
    5

    Note
    In this example, there are 5 possible results for the final amount of milk in the first barn's tank:
    1000: FJ could carry the same bucket back and forth in each trip, leaving the total amount in the first barn's tank unchanged.
    1003: FJ could carry 2 units on Tuesday, then 5 units on Wednesday, then 1 unit on Thursday, and 1 unit on Friday.
    1004: FJ could carry 1 unit on Tuesday, then 5 units on Wednesday, then 1 unit on Thursday, and 1 unit on Friday.
    1007: FJ could carry 1 unit on Tuesday, then 5 units on Wednesday, then 2 units on Thursday, and 5 units on Friday.
    1008: FJ could carry 1 unit on Tuesday, then 5 units on Wednesday, then 1 unit on Thursday, and 5 units on Friday.
    

    题意

    有个很闲的人,他有两个牛奶仓,各有1000单位牛奶,每个仓有10个水桶,这是他周一发现的,然后这个人就开始搞了。周二选仓1的一个桶装满牛奶运到仓2,周三选仓2的一个桶(可能是周二运来那个)装满牛奶运到仓1,周四同周二,周五同周三。周六的时候他想知道仓1有不同奶的数。

    分析

    循环往复,想到模拟,想到dfs每次搜一个结果,看看之前有没,没就+1,开一个数组记录这个桶是仓1还是仓2的

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int INF=0x3f3f3f3f;
    typedef long long ll;
    int baket[25],whose[25],vis[2500]={0},cnt=0;
    void dfs(int day,int suma,int sumb){
    	if(day==6){
    		cnt+=(!vis[suma]);
    		vis[suma]=1;
    		return;
    	}
    	if(day%2==0){
    		for(int i=0;i<20;i++){
    			if(whose[i]==1){
    				whose[i]=2;//a->b
    				dfs(day+1,suma-baket[i],sumb+baket[i]);
    				whose[i]=1;//还原避免影响下次搜索 
    			}
    		}
    	}else{
    		for(int i=0;i<20;i++){
    			if(whose[i]==2){
    				whose[i]=1;//b->a
    				dfs(day+1,suma+baket[i],sumb-baket[i]);
    				whose[i]=2;//还原避免影响下次搜索 
    			}
    		}
    	} 
    }
    int main(){
    	int i;
    	for(i=0;i<20;i++){
    		cin>>baket[i];
    		whose[i]=i/10+1;// a->1 b->2
    	}
    	dfs(2,1000,1000);
    	printf("%d\n",cnt);
    	return 0;
    }
    
    展开全文
  • Back and Forth

    2019-03-15 17:07:00
    题目 ...Farmer John has two milking barns, each of which has a large milk tank as well as a storage closet containing 10 buckets of various sizes. He likes to carry milk back and fort...

    题目

    • Problem Description
      Farmer John has two milking barns, each of which has a large milk tank as well as a storage closet containing 10 buckets of various sizes. He likes to carry milk back and forth between the two barns as a means of exercise. On Monday, Farmer John measures exactly 1000 gallons of milk in the tank of the first barn, and exactly 1000 gallons of milk in the tank of the second barn.

      On Tuesday, he takes a bucket from the first barn, fills it, and carries the milk to the second barn, where he pours it into the storage tank. He leaves the bucket at the second barn.

      On Wednesday, he takes a bucket from the second barn (possibly the one he left on Tuesday), fills it, and carries the milk to the first barn, where he pours it into the storage tank. He leaves the bucket at the first barn.

      On Thursday, he takes a bucket from the first barn (possibly the one he left on Wednesday), fills it, and carries the milk to the second barn, where he pours it into the tank. He leaves the bucket at the second barn.

      On Friday, he takes a bucket from the second barn (possibly the one he left on Tuesday or Thursday), fills it, and carries the milk to the first barn, where he pours it into the tank. He leaves the bucket at the first barn.

      Farmer John then measures the milk in the tank of the first barn. How many possible different readings could he see?

    • Input
      The first line of input contains 10 integers, giving the sizes of the buckets initially at the first barn. The second line of input contains 10 more integers, giving the sizes of the buckets initially at the second barn. All bucket sizes are in the range 1…100.

    • Output
      Please print the number of possible readings Farmer John could get from measuring the milk in the tank of the first barn after Friday.

    • input
      1 1 1 1 1 1 1 1 1 2
      5 5 5 5 5 5 5 5 5 5

    • output
      5

    题意

    有两个仓库初始都存有相同的牛奶1000加仑
    每个仓库都有10个容量不同的桶
    周二周四:从一仓 拿一个桶装满牛奶 倒入二仓
    周三周五:从二仓 拿一个桶装满牛奶 倒入一仓
    可能会拿到相同以前用过的桶
    问周六观察一仓牛奶量可能的情况数量

    思路

    按会不会从二仓把一仓带过去的桶拿回来,如果拿回来一次,则抵消两天变化
    1.带回两个一仓的桶:
    一仓牛奶不变
    2.带回一个一仓的桶:
    一仓牛奶会减少一个一仓桶的容量牛奶,并增加一个二仓桶的容量牛奶
    3.带回零个一仓的桶:
    一仓牛奶会减少两个不同一仓桶的容量牛奶,并增加两个不同二仓桶的容量牛奶

    遍历以上所有的组合即为一仓可能观察到的牛奶数量

    代码

    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    int a[10],b[10];
    const int milk=200;//初始有200milk
    int vis[405];
    
    int main() {
        for(int i=0; i<10; ++i)
            scanf("%d",a+i);
        for(int i=0; i<10; ++i)
            scanf("%d",b+i);
    
        memset(vis,0,sizeof(vis));
    //带回零个一仓的桶
        for(int i=0; i<10; ++i) {//二仓挑两个不同的
            for(int j=0; j<10; ++j)
                if(i!=j)
                    for(int k=0; k<10; ++k)//一仓挑两个不同的
                        for(int l=0; l<10; ++l)
                            if(k!=l)
                                vis[milk+b[i]+b[j]-a[k]-a[l]]++;
        }
    //带回一个一仓的桶
        for(int i=0; i<10; ++i) //都挑一个
            for(int j=0; j<10; ++j)
                vis[milk+b[i]-a[j]]++;
    //带回两个一仓的桶
        vis[200]=1;//不挑
    
        int ans=0;
        for(int i=0; i<=400; ++i) {
            if(vis[i]!=0) ++ans;
        }
        printf("%d\n",ans);
    
        return 0;
    }
    
    展开全文
  • [USACO18DEC] Back and Forth

    2019-03-16 22:21:29
    Description Farmer John has two milking barns, each of which has a large milk tank as well as a storage closet containing10 buckets of various sizes... He likes to carry milk back and forth between t...

     Description

    Farmer John has two milking barns, each of which has a large milk tank as well as a storage closet containing 10 buckets of various sizes. He likes to carry milk back and forth between the two barns as a means of exercise. On Monday, Farmer John measures exactly 1000 gallons of milk in the tank of the first barn, and exactly 1000 gallons of milk in the tank of the second barn.

    On Tuesday, he takes a bucket from the first barn, fills it, and carries the milk to the second barn, where he pours it into the storage tank. He leaves the bucket at the second barn.

    (周二,他从第一个挤奶棚里取出一个桶,并装满牛奶,然后将牛奶运到第二个挤奶棚,并将牛奶倒进奶罐。他把这个桶留在了第二个挤奶棚。)

    On Wednesday, he takes a bucket from the second barn (possibly the one he left on Tuesday), fills it, and carries the milk to the first barn, where he pours it into the storage tank. He leaves the bucket at the first barn.

    (周三,他从第二个挤奶棚里取出一个桶(可能是周二留在这里的),并装满牛奶,然后将牛奶运到第一个挤奶棚,并将牛奶倒进奶罐。他把这个桶留在了第一个挤奶棚。)

    On Thursday, he takes a bucket from the first barn (possibly the one he left on Wednesday), fills it, and carries the milk to the second barn, where he pours it into the tank. He leaves the bucket at the second barn.

    (周四,他从第一个挤奶棚里取出一个桶(可能是周三留在这里的),并装满牛奶,然后将牛奶运到第二个挤奶棚,并将牛奶倒进奶罐。他把这个桶留在了第二个挤奶棚。)

    On Friday, he takes a bucket from the second barn (possibly the one he left on Tuesday or Thursday), fills it, and carries the milk to the first barn, where he pours it into the tank. He leaves the bucket at the first barn.

    (周五,他从第二个挤奶棚里取出一个桶(可能是周二或周四留在这里的),并装满牛奶,然后将牛奶运到第一个挤奶棚,并将牛奶倒进奶罐。他把这个桶留在了第一个挤奶棚。)

    Farmer John then measures the milk in the tank of the first barn. How many possible different readings could he see?

    Input

    The first line of input contains 1010 integers, giving the sizes of the buckets initially at the first barn. The second line of input contains 1010more integers, giving the sizes of the buckets initially at the second barn. All bucket sizes are in the range 1…100.

    Output

    Please print the number of possible readings Farmer John could get from measuring the milk in the tank of the first barn after Friday.

    Example

    input

    1 1 1 1 1 1 1 1 1 2
    5 5 5 5 5 5 5 5 5 5
    

    output

    5
    

    Note

    In this example, there are 5 possible results for the final amount of milk in the first barn's tank:

     

    解析 

    多次搬运之和要要求第一个奶棚可能的读数。

    枚举一下发现:

    • 1000: FJ could carry the same bucket back and forth in each trip, leaving the total amount in the first barn's tank unchanged.
    • 1003: FJ could carry 2 units on Tuesday, then 5 units on Wednesday, then 1 unit on Thursday, and 1 unit on Friday.
    • 1004: FJ could carry 1 unit on Tuesday, then 5 units on Wednesday, then 1 unit on Thursday, and 1 unit on Friday.
    • 1007: FJ could carry 1 unit on Tuesday, then 5 units on Wednesday, then 2 units on Thursday, and 5 units on Friday.
    • 1008: FJ could carry 1 unit on Tuesday, then 5 units on Wednesday, then 1 unit on Thursday, and 5 units on Friday.
    • 四个不同桶
    • 两次不一样(同一只桶去了回来一次)
    • 不变(同一只桶去了回来两次)
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <queue>
    using namespace std;
    int ans[2500],cnt=0;
    int a[11],b[11];
    int main()
    {
        ans[1000]=1;//不变
        int i,j,m,n;
        for(i=1;i<=10;i++)
            scanf("%d",&a[i]);
        for(i=1;i<=10;i++)
            scanf("%d",&b[i]);
        for(i=1;i<=10;i++)
            for(j=1;j<=10;j++)
                ans[1000-a[i]+b[j]]++;
        //-a +a -b +c
        for(i=1;i<=10;i++)
            for(j=1;j<=10;j++)
                for(m=i+1;m<=10;m++)
                    for(n=j+1;n<=10;n++)
                        ans[1000-a[i]+b[j]-a[m]+b[n]]++;//四次不一样
        for(i=0;i<2500;i++)
            if(ans[i])  cnt++;
        printf("%d\n",cnt);
        return 0;
    }

    碎碎念

    此题还有dfs的做法,待更新。

    展开全文
  • <p>How necessary are these and are there any workarounds or improvements that could be made to make switching back and forth a little easier/faster? <p>If it sounds like I'm talking crazy talk ...
  • <p>I am using the routines date2num and num2date and realised that they do not give the same results when I convert back and forth: In [1]: import netCDF4 as nt In [2]: jd0 = 1721424. In [3]: jd &...
  • What I have come to notice that because the InputManager persists through scene changes you need the camera and cursor to do so as well otherwise it throws a bunch of different errors that are really...
  • <div><p>In the latest ... Memory usages are not updated as well. The official 7-Zip works well on this case.</li></ol>该提问来源于开源项目:mcmilk/7-Zip-zstd</p></div>
  • <div><p>Not all languages handle unicode well.</p><p>该提问来源于开源项目:exercism/problem-specifications</p></div>
  • <div><p>Colspan of .footable-row-detail-cell row isnt calculated well when th is used in tbody cos this th wont be count into sum of colum. <p>for example: <p><code><tbody> <code><tr> ...
  • "On Writing Well" has been praised for its sound advice, its clarity and the warmth of its style. It is a book for everybody who wants to learn how to write or who needs to do some writing to get ...
  • You find out what you need to do to give your site the best possible chance to rank well in the search engines. In this book, I show you how to ✓ Make sure that you’re using the right keywords in ...
  • <div><p>This is a meta issue for the work of extending chalk to support the various built-in traits like <code>Sized, <code>Copy, and so forth. <ul><li>[x] Extend <code>TraitDefn</code> with concept ...
  • Completely revised, this edition gives you all the JavaScript basics as well as step-by-step instructions for getting your scripts onto the Web. Before you know it, you could be building interactive ...
  • May be true for real device as well. The Library uses a Configuration for Android Screen Sizes to detect if the device is a tablet. This is results in the wrong value. How about we split the ...
  • Either way, iPhone For Dummies, 9th Edition is the place to start. This book has the step-by-step guidance you need to learn how to use your phone's many features and functions. Newly updated to ...
  • ake an inward journey for a happier, healthier lifeMeditation has been used for centuries to reduce stress, increase energy, and enhance overall health and well-being—so it's no wonder more and more ...
  • <p>In a simple example (as well as real world apps), there is some unexpected behaviour if you have two activities with view models, and a button on each that Navigates from the First to the Second ...
  • TREATMENT RESOURCE MANUAL FOR SPEECH-LANGUAGE PATHOLOGY, 4th edition is an ideal text for students entering into a clinical practicum. Not only are basic therapy and information reporting techniques ...
  • <div><p>one of our customers has an edge case where sometimes they get an inexplicable permissions error on the well-known file. It's a GCE instance, so it should use the 4th method (line 106+...
  • Problems and examples reference a broad range of topics, as well as career areas such as electronics, mechanics, and health, showing students that mathematics is part of everyday life. The text's ...
  • <p>Anyways - long story short - I work (and have worked with for several years) with James Agnew, and he suggested I maybe clean up my original fork/branch a bit and re-submit it to you as a PR....
  • degree in Electrical Engineering and Computer Science as well as a Ph.D. degree in Biophysics and Medical Physics from the University of California, Berkeley (1984). For his doctoral research, he ...
  • <p>For this case, if I only provide Thoonk with hostname and port, then I get an error from RedisClient: <p>Error Ready check failed: Error: ERR operation not permitted <p>I verified that existing ...
  • The Atlas metrics system inside Netflix also has support for bucketized metrics aggregation that we currently can't take advantage of because the data is not placed into fixed buckets. <p>This ...
  • sign as the assignment operator for functions, secondly I added support for R6Class(es), environments (new.env) and a generic RxClass which can be used as well for outline creation. The latter allows...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,781
精华内容 1,112
关键字:

forthwell