2016-2017 ACM Central Region of Russia Quarterfinal Programming Contest

A. Fried Fish

题意:有N条鱼,有一个同时可以煎k条鱼的锅,鱼两个面都要煎;

分析:k*2个面要煎,是否有一种方式可以让锅没有空闲,当时我举了几个例子,确实可以找到,没有证明,注意n<k的情况

#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int main()
{
freopen("INPUT.TXT","r",stdin);
freopen("OUTPUT.TXT","w",stdout);
int x,y;
while(scanf("%d%d",&x,&y)!= EOF)
{
if(2*x<=y)
printf("2\n");
else
{
if((2*x)%y==0)
printf("%d\n",(2*x)/y);
else
printf("%d\n",(2*x)/y+1);
}
}
return 0;
}

B. Hanoi tower

题意:用给出的汉诺塔算法,求出第一次相同时的步数;

分析:

网上有一个公式:先求出n层从A到B的步数:d(n)=d(n-1)*2+1

然后:ans(n)= d(n/3*2-1)+d(n/3-1)+1

勉强这个方案可以看懂,的确要比ans(n)=d(n/32)+d(n/3)或者 2d(n/3) 要小,

但是,最后有一个特判,不是很懂;

回到原题,直接根据给出的算法,打表求解,前几项分别是:

2 9 38 135 542 2079

直接给出公式把:强烈推荐python 写大整数

a = [0]*105
#print a a[1] = 2
a[2] = 9
deta = 97 for i in range(3,103):
if i%2==1:
a[i] = a[i-1]*4+2
else:
a[i] = a[i-1]+deta
deta = 16*deta - 15 cin = open("input.txt","r")
cout = open("output.txt","w") n = int(int(cin.read())/3)
cout.write(str(a[n]))

打表程序:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <set> using namespace std;
typedef long long ll; int k;
int ans;
int num[3]; void hanoi(char x,char y,char z,int n) {
if(n>0) {
hanoi(x,z,y,n-1);
printf("------->%d: %d%d%d\n",k++,--num[x-'a'],++num[y-'a'],num[z-'a']);
//k++;
//num[x-'a']--;
//num[y-'a']++;
//if(num[x-'a']==num[y-'a']&&num[y-'a']==num[z-'a']) {
// ans = k;
//return ;
//}
hanoi(z,y,x,n-1);
}
} int main()
{
freopen("output.txt","w",stdout);
int n;
scanf("%d",&n);
k = 1;
num[0] = n;
hanoi('a','b','c',n);
printf("%d\n",ans);
return 0;
}

D. Weather Station

题意:有8个方向,给出一个字符串,求这个字符串可能是几种方案合成的

分析:乘法原理,d(i) 是前 i 项字符的方案数,当i+1 个字符串可能模棱两可,那么这里就有两种可能,于是:d(i+1)= d(i)*2

#include <bits/stdc++.h>

using namespace std;

const int maxn = 100000 + 5;
char str[maxn];
const int MOD = 1000000000+7; int main()
{ freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%s",str); int len = strlen(str);
int ans = 1;
for(int i=0;i<len;i++)
{
if(str[i]=='N'&&str[i+1]=='E')
ans = ans*2%MOD;
else if(str[i]=='S'&&str[i+1]=='W')
ans = ans*2%MOD;
else if(str[i]=='S'&&str[i+1]=='E')
ans = ans*2%MOD;
else if(str[i]=='N'&&str[i+1]=='W')
ans = ans*2%MOD;
}
printf("%d\n",ans); return 0;
}

E. Cupcakes

题意:有n个学生,来排队吃蛋糕k个,领完后又到队列后面可以继续吃,每个学生最多能吃a_i个,有一个大胃王,每次都吃完a_i,现在大家想让他吃的时候恰好没有蛋糕了,求是不是可能;

分析:贪心极端情况,当轮到大胃王吃的时候,如果,前面的人最少,最多能吃[l,r]个,k在个区间,于是就可以做到;

#include <bits/stdc++.h>

using namespace std;

const int maxn = 100000+5;
long long a[maxn]; int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n;
long long k;
scanf("%d%lld",&n,&k);
long long x = 0;
int flag = -1;
for(int i=0;i<n;i++) {
scanf("%lld",&a[i]);
if(a[i]>x) {
flag = i;
x = max(x,a[i]);
}
} long long l = 0,r=0;
for(int i=0;i<flag;i++) {
l ++;
r +=a[i];
} if(l<=k&&r>=k) {
puts("YES");
return 0;
} while(l<=r) {
l+=x;
r+=x;
for(int i=flag+1;i<n;i++)
{
l++;
r = r + a[i];
}
for(int i=0;i<flag;i++) {
l++;
r = r + a[i];
}
if(l<=k&&r>=k) {
puts("YES");
return 0;
}
else if(l>k)
break;
} puts("KEK");
return 0;
}

G. Sphenic numbers

题意:一个数是否是三个素数的乘积

分析:直接质因数分解

#include<bits/stdc++.h>
using namespace std; const int maxn = 10467397 + 105;
vector<int> primes;
bool bo[maxn+5]; int prime_table() {
int i,j,cnt=0;
bo[0]=bo[1]=true;
for(i=2; i<=sqrt(maxn*1.0); i++)
if(!bo[i]) {
j=i*i;
for(; j<=maxn; j+=i)
bo[j]=true;
}
for(i=0; i<=maxn; i++)
if(!bo[i])
primes.push_back(i);
return primes.size();
} bool add_int(int n){
int e = 0;
for(int i = 0; i < primes.size(); i++){
bool f = true;
while(n % primes[i] == 0){
n /= primes[i];
if(f){
f = false;
e++;
}
}
if(n == 1)
return e == 3;
}
} int main() {
// freopen("in.txt", "r", stdin);
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n;
prime_table();
scanf("%d", &n);
puts(add_int(n) ? "YES" : "NO");
return 0;
}

H. Non-random numbers

题意:生成一个n位的随机数,有多少种数,有三条规则:

  • 没有前导零
  • 第 i 位 不是 i
  • n 位

分析:第一位8种,后面9种,再后面10种,不用写大整数.

#include <bits/stdc++.h>

using namespace std;

int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n;
scanf("%d",&n); unsigned long long ans = 1;
if(n<=9) {
n--;
ans = 8;
for(int i=0;i<n;i++)
ans = ans *9;
cout<<ans<<endl;
}
else {
ans = 8;
for(int i=0;i<8;i++)
ans = ans*9;
cout<<ans;
for(int i=10;i<=n;i++)
printf("%d",0);
puts("");
} return 0;
}

J. Architect of Your Own Fortune

题意:有两种票,可以折叠起来拼成一种超级幸运票,求最多能匹配多少张?

分析:最大匹配

#include <bits/stdc++.h>

using namespace std;

const int maxn = 500+5;

struct BPM
{
int n,m;
vector<int> G[maxn];
int left[maxn];
bool T[maxn]; int right[maxn];
bool S[maxn]; void init(int n,int m)
{
this->n = n;
this->m = m;
for(int i=0; i<n; i++)
G[i].clear();
} void AddEdge(int u,int v)
{
G[u].push_back(v);
} bool match(int u)
{
S[u] = true;
for(int i=0; i<G[u].size(); i++)
{
int v = G[u][i];
if(!T[v])
{
T[v] = true;
if(left[v]==-1||match(left[v]))
{
left[v] = u;
right[u] = v;
return true;
}
}
}
return false;
} int solve()
{
memset(left,-1,sizeof(left));
memset(right,-1,sizeof(right));
int ans = 0;
for(int u=0; u<n; u++)
{
memset(S,0,sizeof(S));
memset(T,0,sizeof(T));
if(match(u))
ans++;
}
return ans;
} } sol; char a[maxn][10];
char b[maxn][10]; int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n,m;
scanf("%d%d",&n,&m); sol.init(n,m);
for(int i=0; i<n; i++)
scanf("%s",a[i]); for(int i=0; i<m; i++)
scanf("%s",b[i]); for(int i=0; i<n; i++)
{
int aa = a[i][0]-'0' + a[i][1] -'0' + a[i][2]-'0';
for(int j=0; j<m; j++)
{
int bb = b[j][3]-'0'+b[j][4]-'0'+b[j][5]-'0';
if(aa==bb)
sol.AddEdge(i,j);
}
} for(int i=0; i<n; i++)
{
int aa = a[i][3]-'0' + a[i][4] -'0' + a[i][5]-'0';
for(int j=0; j<m; j++)
{
int bb = b[j][0]-'0' + b[j][1] -'0' + b[j][2]-'0';
if(aa==bb)
sol.AddEdge(i,j);
}
} printf("%d\n",sol.solve());
for(int i=0;i<n;i++) {
if(sol.right[i]!=-1) {
int j = sol.right[i];
int aa = a[i][0]-'0' + a[i][1] -'0' + a[i][2]-'0';
int bb = b[j][3]-'0'+b[j][4]-'0'+b[j][5]-'0';
if(aa==bb)
printf("AT %s %s\n",a[i],b[j]);
else printf("TA %s %s\n",b[j],a[i]);
}
} return 0;
}

2016-2017 ACM Central Region of Russia Quarterfinal Programming Contest的更多相关文章

  1. 2016-2017 ACM Central Region of Russia Quarterfinal Programming Contest BHanoi tower

    B Hanoi tower It has become a good tradition to solve the “Hanoi tower” puzzle at programming contes ...

  2. 2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple

    我是铁牌选手 这次比赛非常得爆炸,可以说体验极差,是这辈子自己最脑残的事情之一. 天时,地利,人和一样没有,而且自己早早地就想好了甩锅的套路. 按理说不开K就不会这么惨了啊,而且自己也是毒,不知道段错 ...

  3. 【转】2016/2017 Web 开发者路线图

    链接:知乎 [点击查看大图] 原图来自LearnCodeAcademy最火的视频,learncode是YouTube上最火的Web开发教学频道,介绍包括HTML/CSS/JavaScript/Subl ...

  4. 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  5. 训练报告 (2014-2015) 2014, Samara SAU ACM ICPC Quarterfinal Qualification Contest

    Solved A Gym 100488A Yet Another Goat in the Garden   B Gym 100488B Impossible to Guess Solved C Gym ...

  6. 2017 ACM ICPC Asia Regional - Daejeon

    2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...

  7. 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest

    2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...

  8. 2017 ACM/ICPC Shenyang Online SPFA+无向图最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  9. 2017 ACM/ICPC Asia Regional Qingdao Online

    Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submi ...

随机推荐

  1. ESC/POS 控制指令

    ESC/POS  控制指令 HT 横向跳格 [名称] Horizontal tab [格式] ASCII HT Hex 09 Decimal 9 [描述] 将当前位置移动到下一个跳格位置. [注释] ...

  2. 解决Resharper在Core项目中无法执行单元测试的问题

    项目升级core了,resharper最近升级到2018.1版本,但是安装后还是无法直接运行单元测试,昨天小姐姐发了解决方法,贼有用.所以记录一下,给自己以后或者其他遇到此问题的小伙伴用.  解决Re ...

  3. Android耗时操作

    No subscribers registered for event class com.test.MessageEvent import de.greenrobot.event.EventBus; ...

  4. python读取excel表格生成sql语句 第一版

    由于单位设计数据库表·,都用sql.不知道什么原因不用 powerdesign或者ermaster工具,建表很痛苦  作为程序猿当然要想办法解决,用Python写一个程序解决 需要用到 xlrd li ...

  5. MATLAB中的概率论与数理统计

    概率论与数理统计 产生随机数 binornd poissrnd exprnd unidrnd normrnd 概率密度函数(pdf) binopdf poisspdf geopdf unidpdf n ...

  6. nyoj 1023——还是回文——————【区间dp】

    还是回文 时间限制:2000 ms  |  内存限制:65535 KB 难度:3   描述 判断回文串很简单,把字符串变成回文串也不难.现在我们增加点难度,给出一串字符(全部是小写字母),添加或删除一 ...

  7. sp 数据拼接html table表转换xml,发邮件

    USE [BES_ADV] GO /****** Object: StoredProcedure [dbo].[RSP_FN_UNAPPLIED_Mail_Reminder] Script Date: ...

  8. 微信token验证源码分享(c#版)

    在开发时遇到一个问题: 上线后提交申请微信提示"您的服务器没有正确响应token验证...",我查看日志发现根本就没有接收到来自微信的参数. 后来我又记录了微信请求方式和请求的字符 ...

  9. 在 Azure Web 应用中创建 PHP 应用程序

    本分步指南将通过 Azure Web 应用帮助您启动并运行示例 PHP 应用程序.除 PHP 外,Azure Web 应用还支持其他语言,如 Java..NET.Node.JS.Python.Ruby ...

  10. Introduction of Servlet Filter(了解Servlet之Filter)

    API文档中介绍了public Interface Filter(公共接口过滤器) Servlet API文档中是这样介绍的: ‘A filter is an object that performs ...