记录

[f(n) for f,n in zip((max,min,lambda s:float(sum(s))/len(s)),([list(map(int,map(input,':::')))]*3))]
# houses/serializers.py
class HousePlainSerializer(object):
    """
    Serializes a House queryset consisting of dicts with
    the following keys: 'id', 'address', 'country',
    'sq_meters', 'price'.
    """

    @staticmethod
    def serialize_data(queryset):
        """
        Return a list of hashed objects from the given queryset.
        """
        return [
            {
                'id': Hasher.from_pk_and_class(entry['id'], House),
                'address': entry['address'],
                'country': Hasher.from_pk_and_class(entry['country'], Country),
                'sq_meters': entry['sq_meters'],
                'price': entry['price']
            } for entry in queryset
        ]


# houses/views.py
class HouseListAPIView(ListAPIView):
    model = House
    serializer_class = HouseSerializer
    plain_serializer_class = HousePlainSerializer  # <-- added custom serializer
    country = None

    def get_queryset(self):
        country = get_object_or_404(Country, pk=self.country)
        queryset = self.model.objects.filter(country=country)
        return queryset

    def list(self, request, *args, **kwargs):
        # Skipping validation code for brevity
        country = self.request.GET.get("country")
        self.country = Hasher.to_object_pk(country)
        queryset = self.get_queryset()

        data = self.plain_serializer_class.serialize_data(queryset)  # <-- serialize

        return Response(data)

https://www.kancloud.cn/luponu/airflow-doc-zh/889658

马走日 问题

class HorseRides:
    def __init__(self, n, m, x, y):
        self.row = n
        self.column = m
        self.startx = x
        self.starty = y
        self.chessboard = [[0]*self.column for r in range(self.row+1)]
        self.sunx = [1, 1, 2, 2,-1,-1,-2,-2]
        self.suny = [2,-2, 1,-1, 2,-2, 1,-1]
        self.chessboard[self.startx][self.starty] = 1;
        self.count = 0;
    def check(self, x, y):
        if x >= self.row or y >= self.column or x < 0 or y < 0 or self.chessboard[x][y] != 0:
            return 0;
        return 1;
    def ride(self, x, y, step):
        for i in range(8):
            xx = x + self.sunx[i]
            yy = y + self.suny[i]
            if self.check(xx, yy) == 1:
                self.chessboard[xx][yy] = step;
                if step == self.row*self.column:
                    self.output();
                else:
                    self.ride(xx, yy, step+1)
                self.chessboard[xx][yy] = 0
    def output(self):
        self.count = self.count + 1
        print "count = %d" % self.count
        for i in range(self.row):
            print self.chessboard[i]
    def getCount(self):
        return self.count
 
 
if __name__ == "__main__":
    horseride = HorseRides(5,4,0,0)
    horseride.ride(0, 0, 2)
    print "total path: %d" % horseride.getCount()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值