#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = ;
int n;
int avai[maxn], need[maxn];
bool dfs(int cur, int u, int f, bool lap)
{
if(cur == u && lap) return true; if(f + avai[cur] < need[cur]) return false;
f = f+avai[cur]-need[cur];
//cout << f << endl;
if(cur == (u-+n)%n && !lap) lap = true;
if(dfs((cur+)%n, u, f, lap)) return true;
return false;
} int solve()
{
for(int i = ; i < n; i++)
{
if(dfs(i, i, , false)) return i;
//cout << i << endl;
}
return -;
} int main()
{
//freopen("out.txt", "w", stdout);
int T; scanf("%d", &T);
for(int kase = ; kase <= T; kase++)
{
scanf("%d", &n);
int sum1, sum2;
sum1 = sum2 = ;
for(int i = ; i < n; i++)
scanf("%d", &avai[i]), sum1 += avai[i];
for(int i = ; i < n; i++)
scanf("%d", &need[i]), sum2 += need[i];
printf("Case %d: ", kase);
if(sum1 < sum2) printf("Not possible\n");
else
{
int flag = solve();
if(flag == -) printf("Not possible\n");
else printf("Possible from station %d\n", flag+);
}
}
return ;
}

zancun的更多相关文章

  1. 小学生四则运算APP核心代码公布

    Mainactivity类: package com.example.XXSCYS; import java.io.ByteArrayOutputStream; import java.io.File ...

  2. Web前端2019面试总结3(东软集团面试题)

    严禁转载,严禁分享,只供私自鉴赏,请君悉知! 一:基础题 1.什么是margin塌陷?请写出至少三种解决margin塌陷的方法. 答:当两个盒子在垂直方向上设置margin值时,会出现一个有趣的塌陷现 ...

  3. sed 和awk的执行方式

    sed 测试案例: 在有cat的行末开始追加<---,直到有dog的行结束 [root@L shells]# cat catDog.txt snake snake pig bird dog ca ...

随机推荐

  1. Python内置函数:read()

    文章转载于:http://blog.csdn.net/sxingming/article/details/51337768(博主:快递小哥) 1> >>> f=open(r&q ...

  2. altium designer 中器件原理图库中,将一个器件分成几部分是如何操作的?就是如何用part表示?

    在SCH Library的Components中选中你要添加part的器件,tools菜单--new part即可

  3. .netcore 在linux 上运行 Helllo World 例子

    要想在linux上运行netcore ,需要在linux 安装netcore SKD 下面分两步完成, 首先我的操作系统是 Ubuntu 14.04 ,不同版本可以参考 官网给出的连接 https:/ ...

  4. Android SDK下载项的说明

    Tools下 1.android sdk tools 软件开发工具包(software development kit):包括测试.调试.第三方工具.模拟器.数据管理工具等. 2.android sd ...

  5. css3弹性布局语法全解

    本文介绍css3弹性布局的语法 html布局 <div class="box"> <div class="item">1</div ...

  6. 部署和调优 3.2 dns安装配置-2

    配置一个自定义的域,随便定义的,不实际存在. 在配置文件里,增加一个域 vim /etc/named.conf zone "123.com" IN { type master; f ...

  7. ImageView 的 ScaleType

    /** * Options for scaling the bounds of an image to the bounds of this view. 将一个图片的边界缩放到这个view边界的几种选 ...

  8. JS的Prototype属性

    转载至: http://blog.sina.com.cn/s/blog_7045cb9e0100rtoh.html 函数:原型 每一个构造函数都有一个属性叫做原型(prototype,下面都不再翻译, ...

  9. Tensorflow 优化学习

    # coding: utf-8 import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_data pr ...

  10. 基于R语言的RRT算法效率统计