只能把补了的题目放这儿了,先留个坑,怕忘记。

Problem G URAL 1806 Mobile Telegraphs

题意是:给定n个电话号码,每个号码是一个长度为10的仅含'0'~'9'的字符串,每两个电话号码a,b之间能通信,需要满足一下条件之一:

1.b能通过改变a中某一个数字的值获得;

2.b能通过交换a中两个数字获得。

n个电话号码不相同,且相互通信的费用由之间的最长公共前缀长度决定。

分析:

对于一个电话号码逐位判断改变某一位的值得到哪些号码,或者交换某两个数字的得到哪些号码,由此判断该号码能与哪些号码通信,通信费用也可以很快求出。

然后就是dijkstra 或者spfa了。注意map存储LL判断的时候,前导0 可能会被忽略。

另外在spfa或dij里面进行边的转移,而不事先把边求出来可以加速过程。

 #include <bits/stdc++.h>
#define esp 1e-6
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define pb push_back
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define lowbit(x) (x&(-x))
#define mp(a, b) make_pair((a), (b))
#define bit(k) (1<<(k))
#define iin freopen("pow.in", "r", stdin);
#define oout freopen("pow.out", "w", stdout);
#define in freopen("solve_in.txt", "r", stdin);
#define out freopen("solve_out.txt", "w", stdout);
#define bug puts("********))))))");
#define Inout iin oout
#define inout in out #define SET(a, v) memset(a, (v), sizeof(a))
#define SORT(a) sort((a).begin(), (a).end())
#define REV(a) reverse((a).begin(), (a).end())
#define READ(a, n) {REP(i, n) cin>>(a)[i];}
#define REP(i, n) for(int i = 0; i < (n); i++)
#define VREP(i, n, base) for(int i = (n); i >= (base); i--)
#define Rep(i, base, n) for(int i = (base); i < (n); i++)
#define REPS(s, i) for(int i = 0; (s)[i]; i++)
#define pf(x) ((x)*(x))
#define mod(n) ((n))
#define Log(a, b) (log((double)b)/log((double)a))
#define Srand() srand((int)time(0))
#define random(number) (rand()%number)
#define random_range(a, b) (int)(((double)rand()/RAND_MAX)*(b-a) + a) using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<unsigned short> VI;
typedef pair<unsigned short,unsigned short> PII;
typedef vector<PII> VII;
typedef vector<PII, int> VIII;
typedef VI:: iterator IT;
typedef map<string, int> Mps;
typedef map<LL, int> Mpi;
typedef map<int, PII> Mpii;
typedef map<PII, int> Mpiii;
Mpi mps;
const int maxn = ;
const int maxm = + ; unsigned short co[maxn];
unsigned short pa[maxm];
LL a[]; LL s[maxm];
int n;
int d[maxm];
bool inq[maxm]; VII g[maxm];
struct HeapNode
{
int d;
unsigned short u;
HeapNode() {}
HeapNode(int d, unsigned short u):d(d), u(u) {}
bool operator < (const HeapNode &rhs)const
{
return d > rhs.d;
}
};
unsigned short cmp1(LL x, LL y)
{
char ss[][];
sprintf(ss[], "%010I64d", x);
sprintf(ss[] ,"%010I64d", y);
int i = ;
for(i = ; i <= ; i++)
{
if(ss[][i] != ss[][i])
break;
}
return co[i];
}
void bfs(int src)
{
priority_queue<HeapNode> q;
q.push(HeapNode(, src));
d[src] = ;
inq[src] = false;
while(!q.empty())
{
HeapNode u = q.top();
int x = u.u;
int dd = u.d;
q.pop();
if(inq[x])
continue;
inq[x] = true;
char ss[];
sprintf(ss+, "%010I64d", s[x]);
Rep(j, , )
{
int c = ss[-j]-'';
REP(k, )
{
if(k == c)
continue;
LL tmp = s[x] + (k-c)*a[j-];
if(mps.count(tmp))
{
int y = mps[tmp];
int l = cmp1(s[x], s[y]);
if(d[y] > dd + l)
{
pa[y] = x;
d[y] = dd + l;
q.push(HeapNode(d[y], y));
}
}
}
}
Rep(j, , ) for(int k = j+; k <= ; k++)
{
int c1 = ss[-j]-'';
int c2 = ss[-k]-'';
if(c1 == c2)
continue;
LL tmp = s[x] + (c2-c1)*a[j-] + (c1-c2)*a[k-];
if(mps.count(tmp))
{
int y = mps[tmp];
int l = cmp1(s[x], s[y]);
if(d[y] >dd + l)
{
pa[y] = x;
d[y] = dd + l;
q.push(HeapNode(d[y], y));
}
}
}
}
}
VI ans; void print(int s)
{
ans.pb(s);
while()
{
s = pa[s];
ans.pb(s);
if(s == )
break;
}
printf("%d\n", ans.size());
VREP(i, ans.size()-, )
{
printf("%hu%c", ans[i], i == ? '\n' : ' ');
}
}
int main()
{ a[] = ;
Rep(i, , )
a[i] = a[i-]*;
scanf("%d", &n);
REP(i, )
scanf("%hu", co+i);
Rep(i, , n+)
{
scanf("%I64d", s+i);
mps[s[i]] = i;
d[i] = inf;
inq[i] = false;
} bfs();
if(d[n] >= inf)
puts("-1");
else
{
printf("%d\n", d[n]);
print(n);
}
return ;
}

Problem D URAL 1803 The Czechs' Rifles

题意:实际上就是要你求出前n个斐波那契数的k进制表示下,各个位数之和,然后再排序输出。

分析首先可以证明的是,fn <= 2*fn-1,所以fn <= 2^n,所以可以这样求每个斐波那契数的k进制表示下各数位之和,将其表示成cnt进制的数,cnt为不超过n的k的最大次幂,

然后预处理出来小于cnt的各个数的k进制下数位之和。接下来就是通过前两项酸算出当前的斐波那契数,然后并将其k进制下各位加起来。这个过程其实就是模拟的一个大数加法的过程。

 #include <bits/stdc++.h>
#define in freopen("solve_in.txt", "r", stdin);
using namespace std;
const int maxn = + ;
struct Node
{
int id, su;
bool operator < (const Node &rhs)const
{
if(su == rhs.su)
return id < rhs.id;
return su < rhs.su;
}
} ans[maxn];
int sum[maxn];
int dp[][maxn]; int n, k;
int main()
{ scanf("%d%d", &k, &n);
int cnt = ;
while(cnt * k < maxn)
cnt *= k;
for(int i = ; i < maxn; i++)
{
int tmp = i;
while(tmp)
{
sum[i] += tmp%k;
tmp /= k;
}
}
dp[][] = dp[][] = ;
ans[].id = , ans[].id = ;
ans[].su = ans[].su = ;
int st = ;
for(int i = ; i <= n; i++)
{
int delta = ;
int now = i&;
int pre = now^;
ans[i].id = i;
for(int k = ; k < st; k++)
{
dp[now][k] += dp[pre][k] + delta;
if(dp[now][k] >= cnt)
{
delta = dp[now][k]/cnt;
dp[now][k] %= cnt;
}
else delta = ;
ans[i].su += sum[dp[now][k]];
}
if(delta)
dp[now][st++] = delta;
ans[i].su += sum[delta];
}
std::sort(ans+, ans++n);
for(int i = ; i <= n; i++)
printf("%d%c", ans[i].id, i == n ? '\n' : ' ');
return ;
}

NEERC 2010, Eastern subregional contest的更多相关文章

  1. NEERC 2013, Eastern subregional contest

    I. The old Padawan Time limit: 0.5 secondMemory limit: 64 MB Yoda: Use the Force. Yes. Now, the ston ...

  2. NEERC 2014, Eastern subregional contest

    最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...

  3. 2013-2014 ACM-ICPC, NEERC, Eastern Subregional Contest PART (8/10)

    $$2013-2014\ ACM-ICPC,\ NEERC,\ Eastern\ Subregional\ Contest$$ \(A.Podracing\) 首先枚举各个折现上的点,找出最小宽度,然 ...

  4. 2014-2015 ACM-ICPC, NEERC, Eastern Subregional Contest Problem G. The Debut Album

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229669 时间限制:1s 空间限制:64MB 题目大意:给定n,a,b的值 求一个长度为n的 ...

  5. 2014-2015 ACM-ICPC, NEERC, Eastern Subregional Contest Problem H. Pair: normal and paranormal

    题目链接:http://codeforces.com/group/aUVPeyEnI2/contest/229669 时间限制:1s 空间限制:64MB 题目大意:给定一个长度为2n,由n个大写字母和 ...

  6. Round 0: Regionals 2010 :: NEERC Eastern Subregional

    Round 0: Regionals 2010 :: NEERC Eastern Subregional 贴吧题解(官方)? 网上的题解 水 A Murphy's Law 题意:Anka拿着一块涂着黄 ...

  7. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)

    A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...

  8. 【2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D】---暑假三校训练

    2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D Problem D. Distribution in Metagonia Input ...

  9. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

随机推荐

  1. scala学习笔记:理解stream和view

    先来个正常的: scala> (0 to 5).map((x:Int)=>{println(x);x*2}).foreach(println) 0 1 2 3 4 5 0 2 4 6 8 ...

  2. 月下载量上千次的APP源码分享

    在360上面上线了一个月,下载量上千余次.这里把代码都分享出来,供大家学习哈!还包括教大家如何接入广告,赚点小钱花花,喜欢的帮忙顶一个,大神见了勿喷,小学僧刚学Android没多久. 首先介绍这款应用 ...

  3. C#中调用存储过程

    [csharp] view plain copy print? string strsql = "Data Source=192.168.24.53;Initial Catalog=JF_C ...

  4. ###学习《C++ Primer》- 5

    点击查看Evernote原文. // @author: gr // @date: 2014-10-20 // @email: forgerui@gmail.com Part 5: 动态内存(第12章) ...

  5. C# ACM poj1005

    大水题呀 public static void acm1005(int n, float[,] a) { float pi = 3.1415926f, rr; int years; ; i < ...

  6. Java实战之04JavaWeb-02Request和Response

    一.Response和Request的生态环境 二.HttpServletResponse---代表响应对象 1.设置状态码 void setStatus(int sc) 状态码: 200:一切正常 ...

  7. 暑假集训(2)第八弹 ----- Hero(hdu4310)

    K - Hero Crawling in process... Crawling failed Time Limit:3000MS     Memory Limit:65536KB     64bit ...

  8. 此一生 一个纯js的ajax

    /** * 得到ajax对象 */ function getajaxHttp() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp ...

  9. [翻译][MVC 5 + EF 6] 5:Code First数据库迁移与程序部署

    原文:Code First Migrations and Deployment with the Entity Framework in an ASP.NET MVC Application 1.启用 ...

  10. Node.js:JavaScript脚本运行环境

    Node.js https://nodejs.org/ 2016-08-03